Import("ocr.js")

var _textView = null
var fuiClick = null
var currentAppPackName = ''
var ENABLE_BLUE_MODE = true
// printinfoOld(hid.isOn())
var ENABLE_HID_MODE = !agent.isOpen() // 是否启用agent模式
// SystemPrint.log(ENABLE_HID_MODE)
var isHideClick = hui.getCheck('check_645ca066').getValue() == 'true'
var rwl任务栏高度 = parseInt(uiText.findByID(控件ID = 'rwl_gd').getText()) || screen.getStatusBarHeight() || 102 // 默认102
var appname = hui.getCheck("appname").getValue()
var HANGUP_APPNAMES = appname.split(',')
// SystemPrint.log(HANGUP_APPNAMES.find(item => item == '畅听音乐'))
// SystemPrint.log(HANGUP_APPNAMES.find(item => item == '悟空浏览器'))
// SystemPrint.log(JSON.stringify(HANGUP_APPNAMES))

var APP_NAME_MAPPING = [
    { label: '头条搜索极速版', value: 'com.ss.android.article.lite' },
    { label: '今日头条', value: 'com.ss.android.article.news' },
    { label: '红果免费短剧', value: 'com.phoenix.read' },
    { label: '番茄畅听音乐版', value: 'com.xs.fm.lite' },
    { label: '蛋花免费小说', value: 'com.eggflower.read' },
    { label: '常读免费小说', value: 'com.woodleaves.read' },
    { label: '番茄免费小说', value: 'com.dragon.read' },
    { label: '番茄畅听', value: 'com.xs.fm' },
    { label: '有柿', value: 'com.ss.android.article.search' },
    { label: '抖音极速版', value: 'com.ss.android.ugc.aweme.lite' },
    { label: '悟空浏览器', value: 'com.cat.readall' },
    { label: '书旗小说', value: 'com.shuqi.controller' },
    { label: '快手', value: 'com.smile.gifmaker' },
    { label: '快手极速版', value: 'com.kuaishou.nebula' },
    { label: '喜番短剧', value: 'com.kwai.theater' },
    { label: '快手免费小说', value: 'com.kuaishou.kgx.novel' },
    { label: '新氧极速版', value: 'com.youxiang.soyoungapp.mock' },
    { label: '新氧医美', value: 'com.youxiang.soyoungapp' },
    { label: '百度极速版', value: 'com.baidu.searchbox.lite' },
    { label: '抖音火山版', value: 'com.ss.android.ugc.live' },
    { label: '汽水音乐', value: 'com.luna.music' },
    { label: '西瓜视频', value: 'com.ss.android.article.video' },


]
var SKIPAPPSArray = uiCheckBox.findByID('isallowstart').getAllChecked()
var SKIPAPPS = SKIPAPPSArray.join(',')
// var IS_蓝牙设备连接 = uiSwitch.findByID(控件ID = "bluetooth").getOn()


// app.closeApp('com.kuaishou.kgx.novel')

function showClick(percentX, percentY) {

    if (!isHideClick && fuiClick) {
        fuiClick.setPosition(screen.percentToWidth(percentX) - 15, screen.percentToHeight(percentY) - rwl任务栏高度 - 15)
    }
}

// agentOrHidClick(ocrText('备忘录'))
// SystemPrint.log(ocrText('备忘录').getRect().getCenterY())
// SystemPrint.log(ocrText('备忘录').getRealRect().getCenterY())
// fuiClick.setPosition(405,591 - 100)
// click(405,591)
function showClickAbs(absX, absY) {
    if (!isHideClick && fuiClick) {
        fuiClick.setPosition(absX - 15, absY - rwl任务栏高度 - 15)
    }
}

//↓agent点击相关----------------------
/**
 * 默认睡眠2s
 * @param percentX 
 * @param percentY
 */
function click(percentX, percentY, sleepSecond) {
    if (sleepSecond == undefined) sleepSecond = 2;

    if (ENABLE_BLUE_MODE) {
        hid.click(screen.percentToWidth(percentX), screen.percentToHeight(percentY))
    } else {
        if (ENABLE_HID_MODE) {
            // Otg.click(487, 2473)
            // Otg.click(487, 2473)
            Otg.click(screen.percentToWidth(percentX), screen.percentToHeight(percentY))
        } else {
            agent.click(screen.percentToWidth(percentX), screen.percentToHeight(percentY))
        }
    }
    showClick(percentX, percentY)
    if (sleepSecond >= 50) {
        sleep.millisecond(sleepSecond)
    } else {
        sleep.second(sleepSecond)
    }
    showClick(0, 1)
}


/**
 * 默认睡眠2s
 */
function clickAbs(absx, absy, sleepSecond) {
    if (sleepSecond == undefined) sleepSecond = 2;

    if (ENABLE_BLUE_MODE) {
        hid.click(absx, absy)
    } else {
        if (ENABLE_HID_MODE) {
            Otg.click(absx, absy)
        } else {
            agent.click(absx, absy)
        }
    }
    showClickAbs(absx, absy)
    if (sleepSecond >= 50) {
        sleep.millisecond(sleepSecond)
    } else {
        sleep.second(sleepSecond)
    }
    showClick(0, 1)
}

/**
 * 双击 默认睡眠2s
 * @param percentX 
 * @param percentY
 */
function doubleClick(percentX, percentY, sleepSecond) {
    if (sleepSecond == undefined) sleepSecond = 2;
    if (ENABLE_BLUE_MODE) {
        hid.click(screen.percentToWidth(percentX), screen.percentToHeight(percentY))
        sleep.millisecond(200)
        hid.click(screen.percentToWidth(percentX), screen.percentToHeight(percentY))
    } else {
        if (ENABLE_HID_MODE) {
            Otg.click(screen.percentToWidth(percentX), screen.percentToHeight(percentY))
            sleep.millisecond(200)
            Otg.click(screen.percentToWidth(percentX), screen.percentToHeight(percentY))
        } else {
            agent.click(screen.percentToWidth(percentX), screen.percentToHeight(percentY))
            sleep.millisecond(200)
            agent.click(screen.percentToWidth(percentX), screen.percentToHeight(percentY))
        }
    }

    sleep.second(sleepSecond)
}


/**
 * 默认睡眠1s, 按下间隔1500
 * @param percentX 
 * @param percentY
 */
function press(percentX, percentY, millisecond) {
    if (millisecond == undefined) millisecond = 1500;
    if (percentX == undefined) percentX = 0.5;
    if (percentY == undefined) percentY = 0.5;

    if (ENABLE_BLUE_MODE) {
        hid.touchDown(0, x, y)
        sleep.millisecond(millisecond)
        hid.touchUp(0)

        //  hid.touchDown(0,0.5,0.8);   sleep.millisecond(500);  hid.touchUp(0)
    } else {
        if (ENABLE_HID_MODE) {
            // printinfoOld('tetspress')
            // printinfoOld(screen.percentToWidth(percentX))
            // printinfoOld(screen.percentToHeight(percentY))
            //     Otg.touchDown(0, screen.percentToWidth(0.5), screen.percentToHeight(0.5))
            // sleep.millisecond(2000)
            // Otg.touchUp(0)
            var x = screen.percentToWidth(percentX)
            var y = screen.percentToHeight(percentY)
            Otg.touchDown(0, x, y)
            sleep.millisecond(millisecond)
            Otg.touchUp(0)
        } else {
            agent.touchDown(0, screen.percentToWidth(percentX), screen.percentToHeight(percentY))
            sleep.millisecond(millisecond)
            agent.touchUp(0)
        }
    }

    sleep.second(1)
}


/**
 * 默认睡眠2s
 * @param percentX 
 * @param percentY
 * @param offectY
 */
function clickOffectY(percentX, percentY, offectY, sleepSecond) {
    if (sleepSecond == undefined) sleepSecond = 2;


    if (ENABLE_BLUE_MODE) {
        hid.click(screen.percentToWidth(percentX), screen.percentToHeight(percentY) - offectY)
    } else {
        if (ENABLE_HID_MODE) {
            // Otg.click(220, 598)
            Otg.click(screen.percentToWidth(percentX), screen.percentToHeight(percentY) - offectY)
        } else {
            agent.click(screen.percentToWidth(percentX), screen.percentToHeight(percentY) - offectY)
        }
    }
    showClickAbs(screen.percentToWidth(percentX), screen.percentToHeight(percentY) - offectY)
    sleep.second(sleepSecond)
    showClick(0, 1)
}

/**
 * 默认睡眠2s
 * @param percentX 
 * @param percentY
 * @param offectX
 */
function clickOffectX(percentX, percentY, offectX, sleepSecond) {
    if (sleepSecond == undefined) sleepSecond = 2;

    if (ENABLE_BLUE_MODE) {
        hid.click(screen.percentToWidth(percentX) - offectX, screen.percentToHeight(percentY))
    } else {
        if (ENABLE_HID_MODE) {
            Otg.click(screen.percentToWidth(percentX) - offectX, screen.percentToHeight(percentY))
        } else {
            agent.click(screen.percentToWidth(percentX) - offectX, screen.percentToHeight(percentY))
        }
    }
    showClickAbs(screen.percentToWidth(percentX) - offectX, screen.percentToHeight(percentY))
    sleep.second(sleepSecond)
    showClick(0, 1)
}


/**
 * @param dect 
 * @param sleepSecond 默认睡眠2s, > 100 为毫秒
 */
function agentOrHidClick(dect, sleepSecond, cb) {
    if (sleepSecond == undefined) sleepSecond = 2;
    if (dect != null && dect.getRealRect() != null) {
        // printinfoOld(dect)
        // printinfoOld(dect.getRealRect().getCenterX() + ',' + dect.getRealRect().getCenterY())

        if (ENABLE_BLUE_MODE) {
            hid.click(dect.getRealRect().getCenterX(), dect.getRealRect().getCenterY())
        } else {
            if (ENABLE_HID_MODE) {
                // hid.pr(329.5,1580.5)
                // press(0.5, 0.5)
                Otg.click(dect.getRealRect().getCenterX(), dect.getRealRect().getCenterY())
            } else {
                agent.click(dect.getRealRect().getCenterX(), dect.getRealRect().getCenterY())
            }
        }
        showClickAbs(dect.getRect().getCenterX(), dect.getRect().getCenterY())

        if (sleepSecond >= 100) {
            sleep.millisecond(sleepSecond)
        } else {
            sleep.second(sleepSecond)
        }
        cb && cb()
    } else {
        // printinfoOld('未找到')
    }
    showClick(0, 1)
}

/** 不休眠 */
function agentOrHidback() {
    if (ENABLE_BLUE_MODE) {
        hid.back()
        return
    }

    if (ENABLE_HID_MODE) {
        // Otg.back() //hid.back()
        Otg.back()
    } else {
        agent.back()
    }
}

function agentOrHid休眠() {
    if (ENABLE_BLUE_MODE) {
        hid.keyPress(0, 0x66)
        return
    }

    if (ENABLE_HID_MODE) {
        // Otg.back() //hid.back()
        Otg.keyPress(0, 0x66)
    } else {
        hid.keyPress(0, 0x66)
    }
}

function agentOrHidRecents() {
    if (ENABLE_BLUE_MODE) {
        hid.recents()
    } else {
        Otg.recents()
    }
}


/**
 * 点击后默认休眠2秒
 * @param offectY 比如100
 */
function agentOrHidClickOffectY(dect, offectY, sleepSecond, cb) {
    if (sleepSecond == undefined) sleepSecond = 2;
    if (dect != null) {
        var centerX = dect.getRealRect().getCenterX()

        if (ENABLE_BLUE_MODE) {
            hid.click(centerX, dect.getRealRect().getCenterY() - offectY)
        } else {
            if (ENABLE_HID_MODE) {
                Otg.click(centerX, dect.getRealRect().getCenterY() - offectY)
            } else {
                agent.click(centerX, dect.getRealRect().getCenterY() - offectY)
            }
        }

        showClickAbs(centerX, dect.getRealRect().getCenterY() - offectY)
        sleep.second(sleepSecond)

        cb && cb()
    } else {
        // printinfoOld('未找到')
    }
    showClick(0, 1)
}

function agentOrHidClickOffectX(dect, offectX, sleepSecond, cb) {
    if (sleepSecond == undefined) sleepSecond = 2;
    if (dect != null) {
        var centerX = dect.getRealRect().getCenterX()

        if (ENABLE_BLUE_MODE) {
            hid.click(centerX - offectX, dect.getRealRect().getCenterY())
        } else {
            if (ENABLE_HID_MODE) {
                Otg.click(centerX - offectX, dect.getRealRect().getCenterY())
            } else {
                agent.click(centerX - offectX, dect.getRealRect().getCenterY())
            }
        }

        showClickAbs(centerX - offectX, dect.getRealRect().getCenterY())
        sleep.second(sleepSecond)
        cb && cb()
    } else {
        // printinfoOld('未找到')
    }
    showClick(0, 1)
}


function agentOrHidClickAbsoultX(dect, absoultX, sleepSecond, cb) {
    if (sleepSecond == undefined) sleepSecond = 2;
    if (dect != null) {

        if (ENABLE_BLUE_MODE) {
            hid.click(absoultX, dect.getRealRect().getCenterY())
        } else {
            if (ENABLE_HID_MODE) {
                Otg.click(absoultX, dect.getRealRect().getCenterY())
            } else {
                agent.click(absoultX, dect.getRealRect().getCenterY())
            }
        }

        showClickAbs(absoultX, dect.getRealRect().getCenterY())
        sleep.second(sleepSecond)
        cb && cb()
    } else {

    }
    showClick(0, 1)
}


/**默认休眠2s */
function agentOrHidClickAbsoultXOffectY(dect, absoultX, offectY, sleepSecond, cb) {
    if (sleepSecond == undefined) sleepSecond = 2;
    if (dect != null) {

        if (ENABLE_BLUE_MODE) {
            hid.click(absoultX, dect.getRealRect().getCenterY() - offectY)
        } else {
            if (ENABLE_HID_MODE) {
                Otg.click(absoultX, dect.getRealRect().getCenterY() - offectY)
            } else {
                agent.click(absoultX, dect.getRealRect().getCenterY() - offectY)
            }
        }

        showClickAbs(absoultX, dect.getRealRect().getCenterY() - offectY)
        sleep.second(sleepSecond)
        cb && cb()
    } else {

    }
    showClick(0, 1)
}



function pressDect(dect, sleepSecond) {
    if (sleepSecond == undefined) sleepSecond = 2;
    if (dect != null) {
        press(screen.widthToPercent(dect.getRealRect().getCenterX()), screen.heightToPercent(dect.getRealRect().getCenterY()))

        sleep.second(sleepSecond)
    } else {

    }
}


function pressAbsoultX(dect, absoultX, sleepSecond) {
    if (sleepSecond == undefined) sleepSecond = 2;
    if (dect != null) {
        press(screen.widthToPercent(absoultX), screen.heightToPercent(dect.getRealRect().getCenterY()))

        sleep.second(sleepSecond)
    } else {

    }
}


/**点击后默认休眠2秒 */
function agentClickRight(dect, sleepSecond, cb) {
    if (sleepSecond == undefined) sleepSecond = 2;
    if (dect != null) {
        var right = dect.getRealRect().getRight()

        if (ENABLE_BLUE_MODE) {
            hid.click(right - 10, dect.getRealRect().getCenterY())
        } else {
            if (ENABLE_HID_MODE) {
                Otg.click(right - 10, dect.getRealRect().getCenterY())
            } else {
                agent.click(right - 10, dect.getRealRect().getCenterY())
            }
        }

        showClickAbs(right - 10, dect.getRealRect().getCenterY())
        sleep.second(sleepSecond)

        cb && cb()
    } else {
        // printinfoOld('未找到')
    }

    showClick(0, 1)
}

/**向右偏移 */
function agentClickRightOffectRight(dect, offectRX, sleepSecond, cb) {
    if (sleepSecond == undefined) sleepSecond = 2;
    if (dect != null) {
        var right = dect.getRealRect().getRight()

        if (ENABLE_BLUE_MODE) {
            hid.click(right - offectRX, dect.getRealRect().getCenterY())
        } else {
            if (ENABLE_HID_MODE) {
                Otg.click(right - offectRX, dect.getRealRect().getCenterY())
            } else {
                agent.click(right - offectRX, dect.getRealRect().getCenterY())
            }
        }


        showClickAbs(right - offectRX, dect.getRealRect().getCenterY())
        sleep.second(sleepSecond)

        cb && cb()
    } else {
        // printinfoOld('未找到')
    }

    showClick(0, 1)
}

function agentClicLeftOffectLeft(dect, offectLX, sleepSecond, cb) {
    if (sleepSecond == undefined) sleepSecond = 2;
    if (dect != null) {
        var left = dect.getRealRect().getLeft()

        if (ENABLE_BLUE_MODE) {
            hid.click(left + offectLX, dect.getRealRect().getCenterY())
        } else {
            if (ENABLE_HID_MODE) {
                Otg.click(left + offectLX, dect.getRealRect().getCenterY())
            } else {
                agent.click(left + offectLX, dect.getRealRect().getCenterY())
            }
        }

        showClickAbs(left + offectLX, dect.getRealRect().getCenterY())
        sleep.second(sleepSecond)

        cb && cb()
    } else {
        // printinfoOld('未找到')
    }

    showClick(0, 1)
}

function agentClickLeft(dect, sleepSecond) {
    if (sleepSecond == undefined) sleepSecond = 2;
    if (dect != null) {
        var left = dect.getRealRect().getLeft()

        if (ENABLE_BLUE_MODE) {
            hid.click(left + 10, dect.getRealRect().getCenterY())
        } else {
            if (ENABLE_HID_MODE) {
                Otg.click(left + 10, dect.getRealRect().getCenterY())
            } else {
                agent.click(left + 10, dect.getRealRect().getCenterY())
            }
        }

        showClickAbs(left + 10, dect.getRealRect().getCenterY())
        sleep.second(sleepSecond)
    } else {
        printinfoOld('未找到')
    }

    showClick(0, 1)
}

/**
 * 不做任何休眠
 */
function agentSwip(px1, py1, px2, py2) {
    if (ENABLE_BLUE_MODE) {
        hid.swip(screen.percentToWidth(px1), screen.percentToHeight(py1), screen.percentToWidth(px2), screen.percentToHeight(py2), 25, 100, 100)
        return
    }

    if (ENABLE_HID_MODE) {
        Otg.swipe(screen.percentToWidth(px1), screen.percentToHeight(py1), screen.percentToWidth(px2), screen.percentToHeight(py2), 25, 100, 100)
    } else {
        agent.swip(screen.percentToWidth(px1), screen.percentToHeight(py1), screen.percentToWidth(px2), screen.percentToHeight(py2), 2, 100, 100)
    }

}

function agentSwipRealPoint(x1, y1, x2, y2, isFast) {
    if (isFast == undefined) isFast = true
    if (ENABLE_BLUE_MODE) {
        if (isFast) {
            hid.swipe(x1, y1, x2, y2, 25, 100, 100)
        } else {
            hid.swipe(x1, y1, x2, y2, 1, 100, 100)
        }
        return
    }

    if (ENABLE_HID_MODE) {
        if (isFast) {
            Otg.swipe(x1, y1, x2, y2, 25, 100, 100)
        } else {
            Otg.swipe(x1, y1, x2, y2, 1, 100, 100)
        }

    } else {
        if (isFast) {
            agent.swipe(x1, y1, x2, y2, 25, 100, 100)
        } else {
            agent.swipe(x1, y1, x2, y2, 1, 100, 100)
        }
    }
}

/**
 * 不做任何休眠
 */
function agentSwipBig() {
    if (ENABLE_BLUE_MODE) {
        hid.swip(screen.percentToWidth(0.3), screen.percentToHeight(0.85), screen.percentToWidth(0.8), screen.percentToHeight(0.15), 10, 10, 100)
        return
    }

    if (ENABLE_HID_MODE) {
        // swipe(int x1,int y1,int x2,int y2,int 步长,int 按下延时,int 抬起前延时,int 速度,int 抬起次数)
        Otg.swipe(screen.percentToWidth(0.3), screen.percentToHeight(0.85), screen.percentToWidth(0.8), screen.percentToHeight(0.15), 20, 100, 100)
        //Otg.swipe(screen.percentToWidth(0.3), screen.percentToHeight(0.85), screen.percentToWidth(0.8), screen.percentToHeight(0.15), 2, 100, 100)
    } else {
        agent.swip(screen.percentToWidth(0.3), screen.percentToHeight(0.85), screen.percentToWidth(0.8), screen.percentToHeight(0.15), 2, 100, 100)
    }

}

function agentSwipBigDy() {
    if (ENABLE_BLUE_MODE) {
        hid.swip(screen.percentToWidth(0.8), screen.percentToHeight(0.76), screen.percentToWidth(0.5), screen.percentToHeight(0.13), 10, 10, 100)
        return
    }

    if (ENABLE_HID_MODE) {
        // swipe(int x1,int y1,int x2,int y2,int 步长,int 按下延时,int 抬起前延时,int 速度,int 抬起次数)
        Otg.swipe(screen.percentToWidth(0.8), screen.percentToHeight(0.76), screen.percentToWidth(0.5), screen.percentToHeight(0.13), 20, 100, 100)
        //Otg.swipe(screen.percentToWidth(0.3), screen.percentToHeight(0.85), screen.percentToWidth(0.8), screen.percentToHeight(0.15), 2, 100, 100)
    } else {
        agent.swip(screen.percentToWidth(0.8), screen.percentToHeight(0.76), screen.percentToWidth(0.5), screen.percentToHeight(0.13), 2, 100, 100)
    }

}


function agentSwipBigForKS() {
    if (ENABLE_BLUE_MODE) {
        hid.swip(screen.percentToWidth(0.45), screen.percentToHeight(0.75), screen.percentToWidth(0.55), screen.percentToHeight(0.02), 25, 100, 100)
        return
    }

    if (ENABLE_HID_MODE) {
        Otg.swipe(screen.percentToWidth(0.45), screen.percentToHeight(0.75), screen.percentToWidth(0.55), screen.percentToHeight(0.02), 25, 100, 100)
    } else {
        agent.swip(screen.percentToWidth(0.45), screen.percentToHeight(0.75), screen.percentToWidth(0.55), screen.percentToHeight(0.02), 2, 100, 100)
    }

}

function agentSwipBiger() {
    if (ENABLE_BLUE_MODE) {
        hid.swip(screen.percentToWidth(0.3), screen.percentToHeight(0.9), screen.percentToWidth(0.8), screen.percentToHeight(0.05), 25, 100, 100)
        return
    }

    if (ENABLE_HID_MODE) {
        Otg.swipe(screen.percentToWidth(0.3), screen.percentToHeight(0.9), screen.percentToWidth(0.8), screen.percentToHeight(0.05), 25, 100, 100)
    } else {
        agent.swip(screen.percentToWidth(0.3), screen.percentToHeight(0.9), screen.percentToWidth(0.8), screen.percentToHeight(0.05), 2, 100, 100)
    }

}

/**
 * 不做任何休眠
 */
function agentSwipDown(isFast) {
    if (isFast == undefined) isFast = false

    if (ENABLE_BLUE_MODE) {
        hid.swip(screen.percentToWidth(0.4), screen.percentToHeight(0.7),
            screen.percentToWidth(0.6), screen.percentToHeight(0.3), 8, 10, 50)
        return
    }
    if (ENABLE_HID_MODE) {
        Otg.swipe(screen.percentToWidth(0.4), screen.percentToHeight(0.8),
            screen.percentToWidth(0.6), screen.percentToHeight(0.25), isFast ? 25 : 50, 10, 50)
    } else {
        agent.swip(screen.percentToWidth(0.4), screen.percentToHeight(0.8), screen.percentToWidth(0.6), screen.percentToHeight(0.25), isFast ? 10 : 20, 10, 50)
        //  agent.swip(screen.percentToWidth(0.4), screen.percentToHeight(0.8), screen.percentToWidth(0.6), screen.percentToHeight(0.25),  20, 10, 50)
    }
}


/**
 * 不做任何休眠
 */
function agentSwipRight(isFast) {
    if (isFast == undefined) isFast = false

    if (ENABLE_BLUE_MODE) {
        hid.swip(screen.percentToWidth(0.8), screen.percentToHeight(0.5),
            screen.percentToWidth(0.2), screen.percentToHeight(0.5), 8, 10, 50)
        return
    }
    if (ENABLE_HID_MODE) {
        Otg.swipe(screen.percentToWidth(0.8), screen.percentToHeight(0.5),
            screen.percentToWidth(0.2), screen.percentToHeight(0.5), isFast ? 25 : 50, 10, 50)
    } else {
        agent.swip(screen.percentToWidth(0.8), screen.percentToHeight(0.5), screen.percentToWidth(0.2), screen.percentToHeight(0.5), isFast ? 10 : 20, 10, 50)
        //  agent.swip(screen.percentToWidth(0.4), screen.percentToHeight(0.8), screen.percentToWidth(0.6), screen.percentToHeight(0.25),  20, 10, 50)
    }
}

// agentSwipDownMove(false)
function agentSwipDownMove(isFast) {
    if (isFast == undefined) isFast = false

    if (ENABLE_BLUE_MODE) {
        hid.swip(screen.percentToWidth(0.4), screen.percentToHeight(0.62),
            screen.percentToWidth(0.6), screen.percentToHeight(0.35), 30, 100, 100)
        return
    }

    if (ENABLE_HID_MODE) {
        Otg.swipe(screen.percentToWidth(0.4), screen.percentToHeight(0.62),
            screen.percentToWidth(0.6), screen.percentToHeight(0.35), isFast ? 25 : 18, 100, 100)
    } else {
        agent.swip(screen.percentToWidth(0.4), screen.percentToHeight(0.65), screen.percentToWidth(0.6), screen.percentToHeight(0.35), isFast ? 2 : 55, 100, 0)
    }
}


function agentSwipSmallLeft(dect, offectY) {
    if (!dect) {
        return
    }

    var centerY = dect.getRealRect().getCenterY() - offectY

    if (ENABLE_BLUE_MODE) {
        hid.swip(screen.percentToWidth(0.35), centerY, screen.percentToWidth(0.65), centerY, 25, 100, 100)
        return
    }

    if (ENABLE_HID_MODE) {
        Otg.swipe(screen.percentToWidth(0.35), centerY, screen.percentToWidth(0.65), centerY, 20, 100, 100)
    } else {
        agent.swip(screen.percentToWidth(0.35), centerY, screen.percentToWidth(0.65), centerY, 55, 100, 100)
    }
}

function agentSwipSmallDown(isFast) {
    if (isFast == undefined) isFast = false
    if (ENABLE_BLUE_MODE) {
        hid.swip(screen.percentToWidth(0.4), screen.percentToHeight(0.66), screen.percentToWidth(0.6), screen.percentToHeight(0.33), isFast ? 25 : 55, 100, 100)
        return
    }

    if (ENABLE_HID_MODE) {
        Otg.swipe(screen.percentToWidth(0.4), screen.percentToHeight(0.66), screen.percentToWidth(0.6), screen.percentToHeight(0.33), isFast ? 25 : 20, 100, 100)
    } else {
        agent.swip(screen.percentToWidth(0.4), screen.percentToHeight(0.66), screen.percentToWidth(0.6), screen.percentToHeight(0.33), isFast ? 2 : 55, 100, 100)
    }
}

function agentSwipSmallDowner(isFast, absX) {
    if (isFast == undefined) isFast = false
    if (ENABLE_BLUE_MODE) {
        if (absX) {
            hid.swip(absX, screen.percentToHeight(0.56), absX, screen.percentToHeight(0.46), isFast ? 25 : 55, 100, 100)
        } else {
            hid.swip(screen.percentToWidth(0.4), screen.percentToHeight(0.56), screen.percentToWidth(0.6), screen.percentToHeight(0.46), isFast ? 25 : 55, 100, 100)
        }

        return
    }

    if (ENABLE_HID_MODE) {
        if (absX) {
            Otg.swipe(absX, screen.percentToHeight(0.56), absX, screen.percentToHeight(0.46), isFast ? 25 : 20, 100, 100)
        } else {
            Otg.swipe(screen.percentToWidth(0.4), screen.percentToHeight(0.56), screen.percentToWidth(0.6), screen.percentToHeight(0.46), isFast ? 25 : 20, 100, 100)
        }

    } else {
        if (absX) {
            agent.swip(absX, screen.percentToHeight(0.56), absX, screen.percentToHeight(0.46), isFast ? 2 : 55, 100, 100)
        } else {
            agent.swip(screen.percentToWidth(0.4), screen.percentToHeight(0.56), screen.percentToWidth(0.6), screen.percentToHeight(0.46), isFast ? 2 : 55, 100, 100)
        }

    }
}

function agentSwipSmallUper(isFast, absX) {
    if (isFast == undefined) isFast = false
    if (ENABLE_BLUE_MODE) {
        if (absX) {
            hid.swip(absX, screen.percentToHeight(0.46), absX, screen.percentToHeight(0.56), isFast ? 25 : 55, 100, 100)
        } else {
            hid.swip(screen.percentToWidth(0.4), screen.percentToHeight(0.46), screen.percentToWidth(0.6), screen.percentToHeight(0.56), isFast ? 25 : 55, 100, 100)
        }

        return
    }

    if (ENABLE_HID_MODE) {
        if (absX) {
            Otg.swipe(absX, screen.percentToHeight(0.46), absX, screen.percentToHeight(0.56), isFast ? 25 : 20, 100, 100)
        } else {
            Otg.swipe(screen.percentToWidth(0.4), screen.percentToHeight(0.46), screen.percentToWidth(0.6), screen.percentToHeight(0.56), isFast ? 25 : 20, 100, 100)
        }

    } else {
        if (absX) {
            agent.swip(absX, screen.percentToHeight(0.46), absX, screen.percentToHeight(0.56), isFast ? 2 : 55, 100, 100)
        } else {
            agent.swip(screen.percentToWidth(0.4), screen.percentToHeight(0.46), screen.percentToWidth(0.6), screen.percentToHeight(0.56), isFast ? 2 : 55, 100, 100)
        }

    }
}




/**
 * @param times 默认8次
 * @param stepTimes 间隔3秒
 */
function reperatAgentSwipSmallDown循环向下浏览(isFast, times, stepTimes) {
    if (isFast == undefined) isFast = false
    if (times == undefined) times = 8
    if (stepTimes == undefined) stepTimes = 3

    for (var i = 0; i < times; i++) {
        if (ENABLE_BLUE_MODE) {
            hid.swip(screen.percentToWidth(0.4), screen.percentToHeight(0.66), screen.percentToWidth(0.6), screen.percentToHeight(0.33), isFast ? 25 : 55, 100, 100)
        } else {

            if (ENABLE_HID_MODE) {
                Otg.swipe(screen.percentToWidth(0.4), screen.percentToHeight(0.66), screen.percentToWidth(0.6), screen.percentToHeight(0.33), isFast ? 25 : 20, 100, 100)
            } else {
                agent.swip(screen.percentToWidth(0.4), screen.percentToHeight(0.66), screen.percentToWidth(0.6), screen.percentToHeight(0.33), isFast ? 2 : 55, 100, 100)
            }
        }



        sleep.second(stepTimes)
    }

}

function reperatAgentSwipSmallDown循环向下浏览_FOR_KS(isFast, times, stepTimes) {
    if (isFast == undefined) isFast = false
    if (times == undefined) times = 5
    if (stepTimes == undefined) stepTimes = 6

    for (var i = 0; i < times; i++) {
        if (ENABLE_BLUE_MODE) {
            hid.swip(screen.percentToWidth(0.4), screen.percentToHeight(0.66), screen.percentToWidth(0.6), screen.percentToHeight(0.33), isFast ? 25 : 55, 100, 100)
        } else {

            if (ENABLE_HID_MODE) {
                Otg.swipe(screen.percentToWidth(0.4), screen.percentToHeight(0.66), screen.percentToWidth(0.6), screen.percentToHeight(0.33), isFast ? 25 : 20, 100, 100)
            } else {
                agent.swip(screen.percentToWidth(0.4), screen.percentToHeight(0.66), screen.percentToWidth(0.6), screen.percentToHeight(0.33), isFast ? 2 : 55, 100, 100)
            }
        }



        sleep.second(stepTimes)
        agentOrHidClick(ocrText('暂不开', '不开启', '不再提', '再提醒'))
    }

}


/**
 * @param times 默认6次, 即1分钟
 * @param stepSleepTime 默认休息5秒, 实际一次上下滑动为10秒
 */
function reperatAgentUpDownmall循环上下滑动(times, stepSleepTime) {
    if (times == undefined) times = 6
    if (stepSleepTime == undefined) stepSleepTime = 5

    for (var i = 0; i < times; i++) {
        if (ENABLE_BLUE_MODE) {
            hid.swip(screen.percentToWidth(0.45), screen.percentToHeight(0.52), screen.percentToWidth(0.55), screen.percentToHeight(0.49), 35, 100, 100)
        } else {
            if (ENABLE_HID_MODE) {
                // Otg.swipe(screen.percentToWidth(0.3), screen.percentToHeight(0.5), screen.percentToWidth(0.75), screen.percentToHeight(0.4999), 2, 100, 100) 
                Otg.swipe(screen.percentToWidth(0.45), screen.percentToHeight(0.5), screen.percentToWidth(0.55), screen.percentToHeight(0.4999), 55, 100, 100)
            } else {
                agent.swip(screen.percentToWidth(0.45), screen.percentToHeight(0.5), screen.percentToWidth(0.55), screen.percentToHeight(0.4999), 55, 100, 100)
            }
        }


        sleep.second(stepSleepTime)
        if (ENABLE_BLUE_MODE) {
            hid.swip(screen.percentToWidth(0.45), screen.percentToHeight(0.4), screen.percentToWidth(0.55), screen.percentToHeight(0.52), 35, 100, 100)
        } else {
            if (ENABLE_HID_MODE) {
                Otg.swipe(screen.percentToWidth(0.45), screen.percentToHeight(0.4999), screen.percentToWidth(0.55), screen.percentToHeight(0.5), 25, 100, 100)
            } else {
                agent.swip(screen.percentToWidth(0.45), screen.percentToHeight(0.4999), screen.percentToWidth(0.55), screen.percentToHeight(0.5), 2, 100, 100)
            }
        }

        sleep.second(stepSleepTime)
    }

}

/**
 * times = 3, stepSleepTime = 60
 */
function reperatAgentHome(times, stepSleepTime) {
    if (times == undefined) times = 3
    if (stepSleepTime == undefined) stepSleepTime = 60

    for (var i = 0; i < times; i++) {
        agentOrHidHome()
        sleep.second(stepSleepTime)
    }
}


function agentSwipSmallerDown很小间距(isFast) {
    if (isFast == undefined) isFast = false
    if (ENABLE_BLUE_MODE) {
        hid.swip(screen.percentToWidth(0.3), screen.percentToHeight(0.5), screen.percentToWidth(0.75), screen.percentToHeight(0.4999), isFast ? 25 : 55, 100, 100)
        return
    }


    if (ENABLE_HID_MODE) {
        // Otg.swipe(screen.percentToWidth(0.3), screen.percentToHeight(0.5), screen.percentToWidth(0.75), screen.percentToHeight(0.4999), 2, 100, 100) 
        Otg.swipe(screen.percentToWidth(0.3), screen.percentToHeight(0.5), screen.percentToWidth(0.75), screen.percentToHeight(0.4999), isFast ? 25 : 20, 100, 100)
    } else {
        agent.swip(screen.percentToWidth(0.3), screen.percentToHeight(0.5), screen.percentToWidth(0.75), screen.percentToHeight(0.4999), isFast ? 2 : 55, 100, 100)
    }

}

function agentSwipSmallDown上半屏(isFast) {
    if (isFast == undefined) isFast = false
    if (ENABLE_BLUE_MODE) {
        hid.swip(screen.percentToWidth(0.4), screen.percentToHeight(0.45), screen.percentToWidth(0.6), screen.percentToHeight(0.1), isFast ? 25 : 55, 100, 100)
        return
    }

    if (ENABLE_HID_MODE) {
        Otg.swipe(screen.percentToWidth(0.4), screen.percentToHeight(0.45), screen.percentToWidth(0.6), screen.percentToHeight(0.1), isFast ? 25 : 20, 100, 100)
    } else {
        agent.swip(screen.percentToWidth(0.4), screen.percentToHeight(0.45), screen.percentToWidth(0.6), screen.percentToHeight(0.1), isFast ? 2 : 55, 100, 100)
    }

}


function agentSwipSmallUp() {
    if (ENABLE_BLUE_MODE) {
        hid.swip(screen.percentToWidth(0.4), screen.percentToHeight(0.33), screen.percentToWidth(0.6), screen.percentToHeight(0.66), 25, 100, 100)
        return
    }

    if (ENABLE_HID_MODE) {
        Otg.swipe(screen.percentToWidth(0.4), screen.percentToHeight(0.33), screen.percentToWidth(0.6), screen.percentToHeight(0.66), 25, 100, 100)
    } else {
        agent.swip(screen.percentToWidth(0.4), screen.percentToHeight(0.33), screen.percentToWidth(0.6), screen.percentToHeight(0.66), 2, 100, 100)
    }
}

function agentSwipSmallerUp() {
    if (ENABLE_BLUE_MODE) {
        hid.swip(screen.percentToWidth(0.4), screen.percentToHeight(0.4), screen.percentToWidth(0.6), screen.percentToHeight(0.55), 25, 100, 100)
        return
    }

    if (ENABLE_HID_MODE) {
        Otg.swipe(screen.percentToWidth(0.4), screen.percentToHeight(0.4), screen.percentToWidth(0.6), screen.percentToHeight(0.55), 25, 100, 100)
    } else {
        agent.swip(screen.percentToWidth(0.4), screen.percentToHeight(0.4), screen.percentToWidth(0.6), screen.percentToHeight(0.55), 2, 100, 100)
    }
}

function agentSwipSmallerUp很小间距() {
    if (ENABLE_BLUE_MODE) {
        hid.swip(screen.percentToWidth(0.3), screen.percentToHeight(0.49), screen.percentToWidth(0.75), screen.percentToHeight(0.51), 25, 100, 100)
        return
    }

    if (ENABLE_HID_MODE) {
        Otg.swipe(screen.percentToWidth(0.3), screen.percentToHeight(0.4999), screen.percentToWidth(0.75), screen.percentToHeight(0.5), 25, 100, 100)
    } else {
        agent.swip(screen.percentToWidth(0.3), screen.percentToHeight(0.4999), screen.percentToWidth(0.75), screen.percentToHeight(0.51), 2, 100, 100)
    }
}

/**
 * 间隔休息300毫秒
 * @param flag1, flag2, flag3 找到结束 并且休息一秒
 */
function move2Top(moveTimes, millisecond, flag1, flag2, flag3, flag4, flag5) {
    if (millisecond == undefined) millisecond = 300
    if (moveTimes == undefined) moveTimes = 1;
    for (var index = 0; index < moveTimes; index++) {
        // console.time()
        if (flag1 || flag2 || flag3 || flag4 || flag5) {
            var findFlag = ocrText(flag1, flag2, flag3, flag4, flag5)
            if (findFlag && findFlag.getRealRect().getCenterY() < screen.percentToHeight(0.5)) {
                break
            }
        }

        // sleepTime = millisecond - console.timeEnd()
        // if (sleepTime > 10) {
        //     sleep.millisecond(sleepTime)
        // }
        sleep.millisecond(millisecond)

        if (ENABLE_BLUE_MODE) {
            hid.swip(screen.percentToWidth(0.5), screen.percentToHeight(0.15), screen.percentToWidth(0.5), screen.percentToHeight(0.85), 25, 100, 100)
        } else {
            if (ENABLE_HID_MODE) {
                Otg.swipe(screen.percentToWidth(0.5), screen.percentToHeight(0.15), screen.percentToWidth(0.5), screen.percentToHeight(0.85), 25, 100, 100)
            } else {
                agent.swip(screen.percentToWidth(0.5), screen.percentToHeight(0.15), screen.percentToWidth(0.5), screen.percentToHeight(0.85), 3, 100, 100)
            }
        }

    }

    sleep.millisecond(500)
}

function move2TopSmall(moveTimes, millisecond, flag1, flag2, flag3, flag4, flag5) {
    if (millisecond == undefined) millisecond = 300
    if (moveTimes == undefined) moveTimes = 1;
    for (var index = 0; index < moveTimes; index++) {
        if (flag1 || flag2 || flag3 || flag4 || flag5) {
            var findFlag = ocrText(flag1, flag2, flag3, flag4, flag5)
            if (findFlag && findFlag.getRealRect().getCenterY() < screen.percentToHeight(0.5)) {
                break
            }
        }

        sleep.millisecond(millisecond)

        if (ENABLE_BLUE_MODE) {
            hid.swip(screen.percentToWidth(0.5), screen.percentToHeight(0.45), screen.percentToWidth(0.5), screen.percentToHeight(0.65), 55, 100, 100)
        } else {

            if (ENABLE_HID_MODE) {
                Otg.swipe(screen.percentToWidth(0.5), screen.percentToHeight(0.45), screen.percentToWidth(0.5), screen.percentToHeight(0.65), 55, 100, 100)
            } else {
                agent.swip(screen.percentToWidth(0.5), screen.percentToHeight(0.45), screen.percentToWidth(0.5), screen.percentToHeight(0.65), 55, 100, 100)
            }

        }

    }
}

function move2TopSmallFindStop(moveTimes, millisecond, flag1, flag2, flag3, flag4, flag5) {
    if (millisecond == undefined) millisecond = 250
    if (moveTimes == undefined) moveTimes = 1;
    for (var index = 0; index < moveTimes; index++) {
        if (flag1 || flag2 || flag3 || flag4 || flag5) {
            var findFlag = ocrText(flag1, flag2, flag3, flag4, flag5)
            if (findFlag && findFlag.getRealRect().getCenterY() < screen.percentToHeight(0.9)) {
                break
            }
        }

        sleep.millisecond(millisecond)

        if (ENABLE_BLUE_MODE) {
            hid.swip(screen.percentToWidth(0.5), screen.percentToHeight(0.25), screen.percentToWidth(0.5), screen.percentToHeight(0.8), 55, 100, 100)
        } else {

            if (ENABLE_HID_MODE) {
                Otg.swipe(screen.percentToWidth(0.5), screen.percentToHeight(0.25), screen.percentToWidth(0.5), screen.percentToHeight(0.8), 55, 100, 100)
            } else {
                agent.swip(screen.percentToWidth(0.5), screen.percentToHeight(0.25), screen.percentToWidth(0.5), screen.percentToHeight(0.8), 55, 100, 100)
            }

        }

    }
}

function isBlueMode() {
    // hid.home()
    // sleep.millisecond(500)
    if (hui.getCheck('check_07ec64ab').getValue() != 'false') {
        logSleep('当前盗版OTG')
        ENABLE_BLUE_MODE = false

        log('需要加载OTG插件')
        require("Bear_plugin.js")
        if (!OTG_init()) {
            log('OTG初始化未完成!!')
            sleep.second(60)
            hid.swip(screen.percentToWidth(0.8), 10,
                screen.percentToWidth(0.8), screen.percentToHeight(0.5), 25, 100, 0)
            sleep.second(60)
            // stopAll()
            ENABLE_HID_MODE = true
        } else {
            log('OTG初始化完成')
        }
    } else {
        log('当前默认模式为HID/BLUE')
        ENABLE_BLUE_MODE = true
    }

    // log('判断连接方式是蓝牙还是OTG')
    // //找图返回目标数组
    // var detectsblue = opencv.findImagesEx('图色372117.cv');
    // if (detectsblue != null) {
    //     log('初步判断为蓝牙模式')
    //     ENABLE_BLUE_MODE = true
    // } else {
    //     log('初步判断为OTG模式')
    //     ENABLE_BLUE_MODE = false
    // }
    // sleep.second(1)

    // log('二次判断开始')
    // if (ENABLE_BLUE_MODE) {
    //     // hid.home()
    //     hid.swip(screen.percentToWidth(0.8), 10,
    //         screen.percentToWidth(0.8), screen.percentToHeight(0.5), 25, 100, 0)
    // } else {
    //     if (ENABLE_HID_MODE) {
    //         hid.swip(screen.percentToWidth(0.8), 10,
    //             screen.percentToWidth(0.8), screen.percentToHeight(0.5), 25, 100, 0)
    //     } else {
    //         agent.swip(screen.percentToWidth(0.7), 10, screen.percentToWidth(0.7), screen.percentToHeight(0.5), 2, 100, 0)
    //     }
    // }
    // sleep.second(1)


    // var detects = opencv.findImagesEx('图色285535.cv');
    // if (detects != null) {
    //     log('蓝牙模式')
    //     ENABLE_BLUE_MODE = true
    // } else {
    //     log('OTG模式')
    // }

    // sleep.second(1)

    // if (!ENABLE_BLUE_MODE) {
    //     log('加载OTG插件')
    //     require("Bear_plugin.js")
    //     if (!OTG_init()) {
    //         log('OTG初始化未完成!!')
    //         sleep.second(60)
    //         // stopAll()
    //         ENABLE_HID_MODE = true
    //     } else {
    //         log('OTG初始化完成')
    //     }
    // }

    // agentOrHidback()

    // sleep.millisecond(500)

    return ENABLE_BLUE_MODE
}

function lower降低屏幕亮度() {
    log('降低屏幕亮度')
    // Otg.swipe(screen.percentToWidth(0.8), 100,
    //         screen.percentToWidth(0.1), screen.percentToHeight(0.5), 2, 100, 0)
    if (ENABLE_BLUE_MODE) {
        hid.swip(screen.percentToWidth(0.8), 10,
            screen.percentToWidth(0.8), screen.percentToHeight(0.5), 25, 100, 0)
    } else {
        if (ENABLE_HID_MODE) {
            Otg.swipe(screen.percentToWidth(0.8), 10,
                screen.percentToWidth(0.8), screen.percentToHeight(0.5), 25, 100, 0)
        } else {
            agent.swip(screen.percentToWidth(0.7), 10, screen.percentToWidth(0.7), screen.percentToHeight(0.5), 2, 100, 0)
        }
    }
    sleep.second(1)

    var detects = opencv.findImagesEx('图色818618.cv');
    if (detects != null) {
        // var date = new Date();
        // var dayOfWeek = date.getDay(); // 星期日是0，星期一是1，以此类推
        // if (dayOfWeek == 0 || dayOfWeek == 6) {
        //     agentOrHidClickAbsoultX(detects[0], screen.percentToWidth(0.1))
        // } else {
        //     agentOrHidClick(detects[0])
        //     agentSwip(0.6, detects[0].getRect().getCenterY(), 0, detects[0].getRect().getCenterY())
        // }
        agentOrHidClick(detects[0])
        agentSwip(0.6, detects[0].getRect().getCenterY(), 0, detects[0].getRect().getCenterY())
    }

    new floatUI().setSystemPosition(screen.percentToWidth(1), screen.percentToHeight(0.2))

    // if (ENABLE_BLUE_MODE) {
    //     hid.home()
    //     return
    // }
    // if (ENABLE_HID_MODE) {
    //     hid.home() //hid.home()
    // } else {
    //     agent.home()
    // }
    agentOrHidback()
    sleep.second(1)

    agentOrHidHome()
}

function higher调高屏幕亮度() {
    printinfoOld('higher调高屏幕亮度')
    // Otg.swipe(screen.percentToWidth(0.8), 100,
    //         screen.percentToWidth(0.1), screen.percentToHeight(0.5), 2, 100, 0)
    if (ENABLE_BLUE_MODE) {
        hid.swip(screen.percentToWidth(0.8), 10,
            screen.percentToWidth(0.8), screen.percentToHeight(0.5), 25, 100, 0)
    } else {
        if (ENABLE_HID_MODE) {
            Otg.swipe(screen.percentToWidth(0.8), 10,
                screen.percentToWidth(0.8), screen.percentToHeight(0.5), 25, 100, 0)
        } else {
            agent.swip(screen.percentToWidth(0.7), 10, screen.percentToWidth(0.7), screen.percentToHeight(0.5), 2, 100, 0)
        }
    }


    sleep.second(2)

    var detects = opencv.findImagesEx('图色818618.cv');
    if (detects != null) {
        // agentOrHidClick(detects[0])
        agentOrHidClickAbsoultX(detects[0], screen.percentToWidth(0.35))
        // agentSwip(0.6, detects[0].getRect().getCenterY(), 0, detects[0].getRect().getCenterY())
    }

    if (ENABLE_BLUE_MODE) {
        hid.home()
        return
    }
    if (ENABLE_HID_MODE) {
        hid.home()
    } else {
        agent.home()
    }

}
//↑----------------------------------

/**获取星期几 */
function getDayOfWeek() {
    var weekDays = [7, 1, 2, 3, 4, 5, 6];
    var today = new Date();
    return weekDays[today.getDay()];
}



/**
 * 休息时间(秒)
 */
function startsleep开始休眠并弹窗记录() {

    printinfoOld('startsleep开始休眠并弹窗记录')
    if (ENV() == 'test') {
        sleep.second(1)
        return
    }

    if (!isEnableSwitch('is_enable_dcdlxm')) {
        return
    }

    var sleepTime = 2 * 60
    var numdl = get电池电量()
    if (numdl > 80) {
        if (ENABLE_MORE_SLEEP_TIME_更多的睡眠) {
        }
        sleepTime = 2 * 60
    } else if (numdl > 60) {
        if (ENABLE_MORE_SLEEP_TIME_更多的睡眠) {
            sleepTime = 10 * 60 - 10
        }
        sleepTime = 3 * 60 - 10
    } else if (numdl > 30) {
        if (ENABLE_MORE_SLEEP_TIME_更多的睡眠) {
            sleepTime = 10 * 60 - 10
        }
        sleepTime = 9 * 60
    } else {
        if (ENABLE_MORE_SLEEP_TIME_更多的睡眠) {
            sleepTime = 10 * 60 - 10
        }
        sleepTime = 9 * 60
    }
    SystemPrint.warn('开始休眠: ' + sleepTime)
    sleep.second(sleepTime)
}

function getDayOfYear() {

    var currentDate = new Date();
    var year = currentDate.getFullYear();
    var month = currentDate.getMonth() + 1; // 月份从0开始，所以要加1
    var day = currentDate.getDate();
    // var date = new Date()
    // SystemPrint.log(`${year}${month < 10 ? ('0' + month) : month}${day}`)
    // return Math.ceil((date - new Date(date.getFullYear().toString())) / (24 * 60 * 60 * 1000))
    return year + month + day;//new Date().toISOString().slice(0, 10)
}

function getDayOfMonth(splitStr) {
    if (!splitStr) splitStr = ''

    var currentDate = new Date();
    var year = currentDate.getFullYear();
    var month = currentDate.getMonth() + 1; // 月份从0开始，所以要加1
    var day = currentDate.getDate();

    if (day < 10) {
        day = '0' + day
    }
    // var date = new Date()
    // return Math.ceil((date - new Date(date.getFullYear().toString())) / (24 * 60 * 60 * 1000))
    return month < 10 ? `0${month}${splitStr}${day}` : `${month}${splitStr}${day}`;//new Date().toISOString().slice(0, 10)
}

function showLogWindow左半屏小范围() {
    // if (!isEnableSwitch('is_enable_tc')) {
    //     return
    // }
    // logWindow.show()
    // // logWindow.setNoClickModel()
    // logWindow.setWidth(screen.percentToWidth(0.25))
    // logWindow.setHeight(screen.percentToHeight(0.25))
}


function showLogWindow(isForce) {
    // if (isForce == undefined) isForce = false
    // if (!isEnableSwitch('is_enable_tc') && isForce == false) {
    //     return
    // }
    // logWindow.show()
    // logWindow.setWidth(140)
    // logWindow.setNoClickModel()
    // // logWindow.setColor('#FFFFFF')
    // // logWindow.setAlpha(0.5)
    // // logWindow.setPosition(200, 300)
    // // logWindow.setDrag()
    // // logWindow.setNoClickModel()
    // // logWindow.setClickModel()
    // logWindow.setTitle('')
    // logWindow.showModel(0)
    // logWindow.setSize(11)
    // logWindow.setHeight(screen.percentToHeight(0.35))
    // logWindow.setPosition(0, screen.percentToHeight(0.75))

    // logWindow.clear()
    // SystemPrint.log('关闭所有应用')
}

/**closeTime 秒后关闭 , 不在关闭 */
function hideLogWindow(closeTime) {
    if (closeTime == undefined) closeTime = 1
    sleep.second(closeTime)
    logWindow.close()
    sleep.millisecond(1000)
}

/**
 * 是否dect 包含文字
 */
function hasText(dect, str) {
    if (!dect) return false
    return dect.text().includes(str)
}


/**
 *start 包含, end 不包含
 */
function isBetweenTime(start, end, funC) {
    var date = new Date()
    var hour = date.getHours()
    if (hour >= start && hour < end) {
        if (funC) {
            funC()
        }
        return true
    }
    return false
}

function isEndTime() {
    var date = new Date()
    var hour = date.getHours()
    if (hour >= 23 && date.getMinutes() >= 30) {
        return true
    }
    return false
}

function isEndTimeLeft5Min() {
    var date = new Date()
    var hour = date.getHours()
    if (hour >= 23 && date.getMinutes() >= 55) {
        return true
    }
    return false
}

function getEatingTime获取吃饭时间Flag() {
    if (isBetweenTime(6, 9)) {
        return '早饭'
    }
    if (isBetweenTime(11, 14)) {
        return '午饭'
    }
    if (isBetweenTime(17, 20)) {
        return '晚饭'
    }
    if (isBetweenTime(21, 24)) {
        return '夜宵'
    }
    return null
}

/**输出到窗口 */
function printinfoOld(msg) {
    SystemPrint.log(msg)
    write2Text(msg)

    // if (!isEnableSwitch('putongxinxx')) {
    //     return
    // }

    // logWindow.clear()

    // print.log('你好' + '--------------------- ')

    // print.log(msg)
}

function printinfo(msg) {
    SystemPrint.log(msg)
    print.log(msg)
}

function printinfoOldForce(msg, closeTime) {
    if (closeTime == undefined) closeTime = 5
    // logWindow.clear()    
    SystemPrint.log(msg)
    print.log(msg)
    hideLogWindow(closeTime)
}


function printwarn(msg, sleeptime) {
    SystemPrint.warn(msg)
    if (!isEnableSwitch('warminginfo')) {
        return
    }
    if (sleeptime == undefined) sleeptime = 5

    // logWindow.clear()    
    print.warn(msg)

    write2Text(msg + '!!!')
    hideLogWindow(sleeptime)
    // sleep.second(3)
}



function printerr(msg) {
    write2Text(msg + '!!!!!!!!!!!')
    // if (ENV() == 'pro') {
    // print.err(msg)
    // // }
    // SystemPrint.err(msg)
    // sleep.second(5)
}

/**点击 快捷输入, 输入60分钟视频 */
function enter60分钟视频(flag) {
    printinfoOld('快捷输入, 输入60分钟视频')
    // input.install()
    // input.selectInput()


    // input.sendString('test')

    expectView(() => {
        var detects = opencv.findImagesEx('图色436939.cv');
        if (detects != null) {
            return detects[0]
        } else {
            agentOrHidClickAbsoultX(flag, screen.percentToWidth(0.5))
        }
        return null
    }, () => {
        sleep.second(1)
    }, (findView) => {
        agentOrHidClick(findView)
    }, null, 4)


    //点击常用
    var detectscy = opencv.findImagesEx('图色628791.cv');
    if (detectscy == null) {
        var ocr1 = opencv.OCREx('图色817308.cv');
        if (ocr1 != null && ocr1.getAllString().includes('常用')) {
            detectscy = ocr1.getAllDetect()
        }
    }
    if (detectscy != null) {
        agentOrHidClick(detectscy[0], 1)
    }


    // switch (index) {
    //     case 1:
    //         //60分钟
    //         //找图返回目标数组
    //         // var detects60fz = opencv.findImagesEx('图色563011.cv');
    //         // if (detects60fz != null) {
    //         //     agentOrHidClick(detects60fz[0])
    //         // }
    //         agentOrHidClick(ocrTextInRegion(0, 0.45, 0.7, 1, '60分钟省流长视频倒计时1'))
    //         break;
    //     case 2:
    //         //60分钟
    //         // var detects60fz = opencv.findImagesEx('图色291810.cv');
    //         // if (detects60fz != null) {
    //         //     agentOrHidClick(detects60fz[0])
    //         // }
    //         agentOrHidClick(ocrTextInRegion(0, 0.45, 0.7, 1, '60分钟省流长视频倒计时2'))
    //         break;
    //     case 3:
    //         //60分钟
    //         //找图返回目标数组
    //         // var detects60fz = opencv.findImagesEx('图色785498.cv');
    //         // if (detects60fz != null) {
    //         //     agentOrHidClick(detects60fz[0])
    //         // }
    //         agentOrHidClick(ocrTextInRegion(0, 0.45, 0.7, 1, '60分钟省流长视频倒计时3'))

    //         break;
    //     default:
    //         // var detects60fz = opencv.findImagesEx('图色563011.cv');
    //         // if (detects60fz != null) {
    //         //     agentOrHidClick(detects60fz[0])
    //         // }
    //         agentOrHidClick(ocrTextInRegion(0, 0.45, 0.85, 1, '60分钟省流长视频倒计时'))
    //         break;
    // }
    agentOrHidClick(ocrTextMoreInRegion(0, 0.45, 0.85, 1, '长视频黑屏', '60分钟', '0分钟长视频', '省流长视频', '频黑屏'))

    var flagsearch = ocrTextInRegion(0, 0, 1, 0.2, '搜索')
    if (!flagsearch) {
        //找图返回目标数组
        var detects = opencv.findImagesEx('图色848962.cv');
        if (detects != null) {
            flagsearch = detects[0]
        }
    }
    agentClickRight(flagsearch)
}

/**点击 快捷输入, 输入120分钟视频 */
function enter120分钟视频() {

    expectView(() => {
        var detects = opencv.findImagesEx('图色436939.cv');
        if (detects != null) {
            return detects[0]
        }
        return null
    }, () => {
        sleep.second(1)
    }, (findView) => {
        agentOrHidClick(findView)
    }, null, 4)


    //点击常用
    var detectscy = opencv.findImagesEx('图色628791.cv');
    if (detectscy != null) {
        agentOrHidClick(detectscy[0])
    }

    //120分钟
    var detects120fz = opencv.findImagesEx('图色291810.cv');
    if (detects120fz != null) {
        agentOrHidClick(detects120fz[0])
    }

    var flagsearch = ocrText('搜索')
    if (!flagsearch) {
        //找图返回目标数组
        var detects = opencv.findImagesEx('图色848962.cv');
        if (detects != null) {
            flagsearch = detects[0]
        }
    }
    agentOrHidClick(flagsearch)
}


/**
 * @param functionExpect 期望
 * @param stepFunc 每次执行, 直接找到不执行 stepTimes 从1开始
 * @param thenToDo 成功进入 
 * @param failTodo 失败
 * @param repeatMaxTimes 默认3次 本身不做任何的休眠
 */
function expectView(functionExpect, stepFunc, thenToDo, failTodo, repeatMaxTimes, stepTimes) {
    if (repeatMaxTimes == undefined) repeatMaxTimes = 3;
    if (stepTimes == undefined) stepTimes = 1;

    var expectResult = functionExpect(stepTimes)
    if (expectResult) {
        if (thenToDo) {
            thenToDo(expectResult, stepTimes)
        }
    } else {
        if (repeatMaxTimes >= 0) {
            stepFunc && stepFunc(stepTimes)
            expectView(functionExpect, stepFunc, thenToDo, failTodo, repeatMaxTimes - 1, stepTimes + 1)
        } else {
            if (failTodo) {
                failTodo()
            }
        }
    }
}

/**
 * @param functionExpect 期望
 * @param stepFunc 每次执行, 直接找到不执行 stepTimes 从1开始
 * @param thenToDo 成功进入 
 * @param failTodo 失败
 * @param repeatMaxTimes 默认5次 每次休眠 1秒
 */
function expectViewSample(functionExpect, stepFunc, thenToDo, failTodo, repeatMaxTimes, stepTimes) {
    if (repeatMaxTimes == undefined) repeatMaxTimes = 5;
    if (stepTimes == undefined) stepTimes = 1;

    var expectResult = functionExpect(stepTimes)
    if (expectResult) {
        if (thenToDo) {
            thenToDo(expectResult, stepTimes)
        }
        return expectResult
    } else {
        if (repeatMaxTimes >= 0) {
            stepFunc && stepFunc(stepTimes)
            sleep.second(1)
            return expectViewSample(functionExpect, stepFunc, thenToDo, failTodo, repeatMaxTimes - 1, stepTimes + 1)
        } else {
            if (failTodo) {
                failTodo()
            }
            return null
        }
    }
}

/**
 * @param callBack 回调(stepTimes: 执行次数, allTimes: 执行总的时间秒, canBreak)
 * @param second 执行多少秒默认60*60
 * @param stepSecond 每次执行的间隔多少秒, 默认5s
 */
function whilestep(callBack, second, stepSecond, stepEnd) {
    if (second == undefined) second = 60 * 60
    if (stepSecond == undefined) stepSecond = 5
    var allTimes = 0 // 总计多少秒
    var stepTimes = 0
    var sleepTime = 0
    printinfoOld('执行多少秒: ' + second)
    while (true) {
        console.time()
        if (allTimes >= (second)) {
            break
        }
        stepTimes = stepTimes + 1
        allTimes = allTimes + stepSecond

        if (callBack) {
            callBack(stepTimes, allTimes, () => {
                allTimes = second
            })
        }

        sleepTime = stepSecond * 1000 - console.timeEnd()
        if (sleepTime > 100) {
            sleep.millisecond(sleepTime)
        }

        if (stepEnd) {
            stepEnd(() => {
                allTimes = second
            })
        }
        // sleep.millisecond(stepSecond * 1000)
    }
}

function whilestepStandom(callBack, second, stepSecond) {
    if (second == undefined) second = 60 * 60
    if (stepSecond == undefined) stepSecond = 5
    var allTimes = 0 // 总计多少秒
    var stepTimes = 0
    var sleepTime = 0
    printinfoOld('执行多少秒: ' + second)
    while (true) {
        // console.time()
        if (allTimes >= (second)) {
            break
        }
        stepTimes = stepTimes + 1
        allTimes = allTimes + stepSecond

        if (callBack) {
            callBack(stepTimes, allTimes, () => {
                allTimes = second
            })
        }

        // sleepTime = stepSecond * 1000 - console.timeEnd()
        // if (sleepTime > 100) {
        //     sleep.millisecond(sleepTime)
        // }
        sleep.millisecond(stepSecond * 1000)
    }
}

/**
 * @param onInit 初始化回调
 * @param onStep 
 * @param excuteSecond 执行多少秒默认60*60
 * @param stepSecond 默认每隔5s执行
 */
function startThredTask(onInit, onStep, excuteSecond, stepSecond) {
    if (stepSecond == undefined) stepSecond = 5
    if (excuteSecond == undefined) excuteSecond = 60 * 60

    if (!isEnableSwitch('is_enable_threadtask')) {
        onInit()

        whilestep((steptimes) => {
            onStep(steptimes)
        }, excuteSecond, stepSecond)
        return
    }

    var threadTask = new thread();

    threadTask.runJsCode(() => {
        onInit()

        whilestep((steptimes) => {
            onStep(steptimes)
        }, excuteSecond, stepSecond)
    }, "子线程")

    sleep.second(excuteSecond)
    if (threadTask && threadTask.isAlive()) {
        threadTask.stop()
    }
}

/**
 * 默认超时10分钟结束
 */
function startThredTaskMaxTime超时结束(onTask, maxSecond) {
    if (maxSecond == undefined) maxSecond = 10 * 60

    if (!isEnableSwitch('is_enable_threadtask')) {
        onTask()
        return
    }

    var threadTask = new thread();
    var isCanBreak = false
    threadTask.runJsCode(() => {
        onTask()
        isCanBreak = true
    }, "最大休眠子线程")

    whilestep((steptimes, allTimes, canBreak) => {
        if (isCanBreak) {
            canBreak()
        }
    }, maxSecond, 5)

    if (threadTask && threadTask.isAlive()) {
        threadTask.stop()
    }
}

/**
 * 先进行检测, 没有就先返回
 * @param exceptFuncView 
 * @param repeatMaxTimes 2
 * @param sleepTime 默认2s
 */
function backUntilFindView(exceptFuncView, repeatMaxTimes, sleepTime, stepFunc) {
    if (repeatMaxTimes == undefined) repeatMaxTimes = 2;
    if (sleepTime == undefined) sleepTime = 2;
    var flag = exceptFuncView()
    if (flag) {
        return flag
    }

    while (!flag) {
        agentOrHidback()
        repeatMaxTimes = repeatMaxTimes - 1
        if (repeatMaxTimes <= 0) {
            break
        }
        sleep.millisecond(sleepTime * 1000)
        if (stepFunc) {
            stepFunc()
        }
        flag = exceptFuncView()
    }

    return flag
}

/**循环向下浏览期望找到用户自定义的view */
function repeatFindView(exceptFuncView, findViewFunc, maxTimes) {
    if (maxTimes == undefined) maxTimes = 7;
    var findView = exceptFuncView()
    if (findView) {
        if (findViewFunc) findViewFunc(findView)
        return findView
    }

    while (findView == null) {

        agentSwipDownMove(false)
        sleep.millisecond(1800)

        findView = exceptFuncView()

        // printinfoOld(findView.getRealRect().getTop())
        maxTimes = maxTimes - 1
        if (maxTimes <= 0) {
            break
        }
    }

    if (findView != null) {
        if (findViewFunc) {
            findViewFunc(findView)
        }
    }

    return findView
}

function moveUp2FindWid(funC, text, canBreak) {
    var maxTimes = parseInt(uiText.findByID(控件ID = 'move_maxtimes').getText())
    var findView = ocrText(text)

    while (findView == null
        || findView.getRealRect().getTop() > screen.percentToHeight(0.88)
        || findView.getRealRect().getBottom() < screen.percentToHeight(0.1)) {

        if (findView == null) {

            agentSwipDownMove(false)
            sleep.millisecond(1800)
        } else {
            printinfoOld(findView)
            if (findView.getRealRect().getBottom() < screen.percentToHeight(0.1)) {
                agentSwipSmallUp()
            }
            if (findView.getRealRect().getTop() > screen.percentToHeight(0.88)) {
                agentSwipSmallDown(false)
                sleep.millisecond(1800)
            }
        }

        findView = ocrText(text)

        // printinfoOld(findView.getRealRect().getTop())
        maxTimes = maxTimes - 1
        if (maxTimes <= 0) {
            break
        }

        if (canBreak && canBreak()) {
            printinfoOld('移动到底部了!!!')
            break
        }
    }

    if (findView != null) {
        if (funC) {
            funC(findView)
        }
    }
}

function moveUpHigher2FindWid(funC, text, canBreak) {
    var maxTimes = parseInt(uiText.findByID(控件ID = 'move_maxtimes').getText())
    var findView = ocrText(text)

    while (findView == null
        || findView.getRealRect().getTop() > screen.percentToHeight(0.76)
        || findView.getRealRect().getBottom() < screen.percentToHeight(0.15)) {

        if (findView == null) {

            agentSwipDownMove(false)
            sleep.millisecond(1800)
        } else {
            printinfoOld(findView)
            if (findView.getRealRect().getBottom() < screen.percentToHeight(0.15)) {
                agentSwipSmallUp()
            }
            if (findView.getRealRect().getTop() > screen.percentToHeight(0.76)) {
                agentSwipSmallDown(false)
                sleep.millisecond(1800)
            }
        }

        findView = ocrText(text)

        // printinfoOld(findView.getRealRect().getTop())
        maxTimes = maxTimes - 1
        if (maxTimes <= 0) {
            break
        }

        if (canBreak && canBreak()) {
            printinfoOld('移动到底部了!!!')
            break
        }
    }

    if (findView != null) {
        if (funC) {
            funC(findView)
        }
    }
}

function moveUpSmaller2FindWid(funC, text1, text2, text3, text4, text5, canBreak) {
    var maxTimes = parseInt(uiText.findByID(控件ID = 'move_maxtimes').getText())
    var findView = ocrText(text1, text2, text3, text4, text5)

    while (findView == null
        || findView.getRealRect().getTop() > screen.percentToHeight(0.88)
        || findView.getRealRect().getBottom() < screen.percentToHeight(0.1)) {

        if (findView == null) {

            agentSwipSmallDown()
            sleep.millisecond(1800)
        } else {
            printinfoOld(findView)
            if (findView.getRealRect().getBottom() < screen.percentToHeight(0.1)) {
                agentSwipSmallUp()
            }
            if (findView.getRealRect().getTop() > screen.percentToHeight(0.88)) {
                agentSwipSmallDown()
                sleep.millisecond(1800)
            }
        }

        if (typeof (text2) == 'function') {
            findView = ocrText(text1)
            if (text2()) {
                printinfoOld('移动到底部了!!!')
                break;
            }
        }

        if (typeof (text3) == 'function') {
            findView = ocrText(text1, text2)
            if (text3()) {
                printinfoOld('移动到底部了!!!')
                break;
            }
        }

        if (typeof (text4) == 'function') {
            findView = ocrText(text1, text2, text3)
            if (text4()) {
                printinfoOld('移动到底部了!!!')
                break;
            }
        }

        if (typeof (text5) == 'function') {
            findView = ocrText(text1, text2, text3, text4)
            if (text5()) {
                printinfoOld('移动到底部了!!!')
                break;
            }
        }


        findView = ocrText(text1, text2, text3, text4, text5)

        // printinfoOld(findView.getRealRect().getTop())
        maxTimes = maxTimes - 1
        printinfoOld(maxTimes)
        if (maxTimes <= 0) {
            break
        }

        if (canBreak && canBreak()) {
            printinfoOld('移动到底部了!!!')
            break
        }
    }

    if (findView != null) {
        if (funC) {
            funC(findView)
        }
    }
}



function get界面采样点() {
    var checkPoints = [
        { x: 0.25, y: 0.25 },
        { x: 0.25, y: 0.5 },
        { x: 0.25, y: 0.75 },
        { x: 0.5, y: 0.25 },
        { x: 0.5, y: 0.5 },
        { x: 0.5, y: 0.75 },
        { x: 0.75, y: 0.25 },
        { x: 0.75, y: 0.5 },
        { x: 0.75, y: 0.75 },
        // 添加更多坐标点  
        // ... 其他坐标  
    ];

    // 首次截图并获取各点RGB值  
    // 定义要检查的坐标列表  
    // 首次截图并获取各点RGB值  
    var img = screen.screenShotFull();
    var rgbValues = [];
    for (var point of checkPoints) {
        var rgb = img.getPointRGB(point.x, point.y);
        rgbValues.push(rgb);
    }

    return rgbValues
}


function check界面是否不再变化(rgbValues) {
    var checkPoints = [
        { x: 0.25, y: 0.25 },
        { x: 0.25, y: 0.5 },
        { x: 0.25, y: 0.75 },
        { x: 0.5, y: 0.25 },
        { x: 0.5, y: 0.5 },
        { x: 0.5, y: 0.75 },
        { x: 0.75, y: 0.25 },
        { x: 0.75, y: 0.5 },
        { x: 0.75, y: 0.75 },
        // 添加更多坐标点  
        // ... 其他坐标  
    ];

    var imgNext = screen.screenShotFull();

    // 比较两次截图的RGB值  
    var isSceneChanged = false;
    for (var i = 0; i < checkPoints.length; i++) {
        var newRgb = imgNext.getPointRGB(checkPoints[i].x, checkPoints[i].y);
        if (rgbValues[i][0] !== newRgb[0] ||
            rgbValues[i][1] !== newRgb[1] ||
            rgbValues[i][2] !== newRgb[2]) {
            isSceneChanged = true;
            break; // 发现变化就跳出循环  
        }
    }

    if (isSceneChanged) {
        // console.log('画面有变化');
        return false
    } else {
        // console.log('画面无变化');
        return true
    }

}


function is界面不再变化(sleepTime) {
    if (sleepTime == undefined) sleepTime = 5000
    // 方法2：这里是多个截图点进行检验  

    // 定义要检查的坐标列表,,  
    var checkPoints = [
        { x: 0.25, y: 0.25 },
        { x: 0.25, y: 0.5 },
        { x: 0.25, y: 0.75 },
        { x: 0.5, y: 0.25 },
        { x: 0.5, y: 0.5 },
        { x: 0.5, y: 0.75 },
        { x: 0.75, y: 0.25 },
        { x: 0.75, y: 0.5 },
        { x: 0.75, y: 0.75 },
        // 添加更多坐标点  
        // ... 其他坐标  
    ];

    // 首次截图并获取各点RGB值  
    // 定义要检查的坐标列表  
    // 首次截图并获取各点RGB值  
    var img = screen.screenShotFull();
    var rgbValues = [];
    for (var point of checkPoints) {
        var rgb = img.getPointRGB(point.x, point.y);
        rgbValues.push(rgb);
    }
    console.log("首次截图RGB值:", rgbValues);

    // var thread = new startThredTask
    // 等待一段时间后再次截图  
    sleep.millisecond(sleepTime);
    var imgNext = screen.screenShotFull();

    // 比较两次截图的RGB值  
    var isSceneChanged = false;
    for (var i = 0; i < checkPoints.length; i++) {
        var newRgb = imgNext.getPointRGB(checkPoints[i].x, checkPoints[i].y);
        if (rgbValues[i][0] !== newRgb[0] ||
            rgbValues[i][1] !== newRgb[1] ||
            rgbValues[i][2] !== newRgb[2]) {
            isSceneChanged = true;
            break; // 发现变化就跳出循环  
        }
    }

    if (isSceneChanged) {
        console.log('画面有变化');
        return false
    } else {
        console.log('画面无变化');
        return true
    }

    //这是另一种方法

}

function moveUpSmaller2FindWidUntilNoChange(funC, notFind, text1, text2) {
    var maxTimes = 100
    var times = 0
    var findView = ocrText(text1, text2)

    while (findView == null
        || findView.getRealRect().getTop() > screen.percentToHeight(0.75)
        || findView.getRealRect().getBottom() < screen.percentToHeight(0.25)) {


        var rgbs = get界面采样点()
        if (findView == null) {

            agentSwipSmallDown()
            sleep.millisecond(1800)
        } else {
            printinfoOld(findView)
            if (findView.getRealRect().getBottom() < screen.percentToHeight(0.2)) {
                agentSwipSmallUp()
            }
            if (findView.getRealRect().getTop() > screen.percentToHeight(0.8)) {
                agentSwipSmallDown()
                sleep.millisecond(1800)
            }
        }

        // if (typeof (text2) == 'function') {
        //     findView = ocrText(text1)
        //     if (text2()) {
        //         printinfoOld('移动到底部了!!!')
        //         break;
        //     }
        // }



        findView = ocrText(text1, text2)

        // printinfoOld(findView.getRealRect().getTop())
        maxTimes = maxTimes - 1
        printinfoOld(maxTimes)
        if (maxTimes <= 0) {
            break
        }

        if (check界面是否不再变化(rgbs)) {
            times = times + 1
            printinfoOld('界面不再变化!!!')
            if (times >= 2) {
                if (notFind) {
                    notFind()
                }

                break
            }
        }

        // if (canBreak && canBreak()) {
        //     printinfoOld('移动到底部了!!!')
        //     break
        // }
    }

    if (findView != null) {
        if (funC) {
            funC(findView)
        }
    }
}


function moveUp2FindWidTxtMore全屏(funC, text1, text2, text3, text4, text5, canBreak) {
    var maxTimes = parseInt(uiText.findByID(控件ID = 'move_maxtimes').getText())
    var findView = ocrText(text1, text2, text3, text4, text5)

    log('开始查找' + text1 + '次数' + maxTimes)
    while (findView == null) {

        if (findView == null) {
            agentSwipDownMove(false)
            sleep.millisecond(2200)
        } else {
            if (findView.getRealRect().getBottom < screen.percentToHeight(0.1)) {
                agentSwipSmallUp()
            }
            if (findView.getRealRect().getTop() > screen.percentToHeight(0.88)) {
                agentSwipSmallDown()
                sleep.millisecond(1800)
            }
        }

        if (typeof (text2) == 'function') {
            findView = ocrText(text1)
            if (text2()) {
                printinfoOld('移动到底部了!!!')
                break;
            }
        }

        if (typeof (text3) == 'function') {
            findView = ocrText(text1, text2)
            if (text3()) {
                printinfoOld('移动到底部了!!!')
                break;
            }
        }

        if (typeof (text4) == 'function') {
            findView = ocrText(text1, text2, text3)
            if (text4()) {
                printinfoOld('移动到底部了!!!')
                break;
            }
        }

        if (typeof (text5) == 'function') {
            findView = ocrText(text1, text2, text3, text4)
            if (text5()) {
                printinfoOld('移动到底部了!!!')
                break;
            }
        }


        findView = ocrText(text1, text2, text3, text4, text5)

        maxTimes = maxTimes - 1
        if (maxTimes <= 0) {
            break
        }
        2
        if (canBreak && canBreak()) {
            log('移动到底部了!!!')
            break
        }
    }

    if (findView != null) {
        if (funC) {
            funC(findView)
        }
    }
}

function moveUp2FindWidTxtMore(funC, text1, text2, text3, text4, text5, canBreak, failBack) {
    var maxTimes = parseInt(uiText.findByID(控件ID = 'move_maxtimes').getText())
    var findView = ocrText(text1, text2, text3, text4, text5)

    log('开始查找' + text1 + '次数' + maxTimes)
    while (findView == null
        || findView.getRealRect().getTop() > screen.percentToHeight(0.88)
        || findView.getRealRect().getBottom() < screen.percentToHeight(0.1)) {

        if (findView == null) {
            agentSwipDownMove(false)
            sleep.millisecond(2000)
        } else {
            if (findView.getRealRect().getBottom < screen.percentToHeight(0.1)) {
                agentSwipSmallUp()
                sleep.millisecond(2000)
            }
            if (findView.getRealRect().getTop() > screen.percentToHeight(0.88)) {
                agentSwipSmallDown()
                sleep.millisecond(2000)
            }
        }

        if (typeof (text2) == 'function') {
            findView = ocrText(text1)
            if (text2()) {
                printinfoOld('移动到底部了!!!')
                break;
            }
        }

        if (typeof (text3) == 'function') {
            findView = ocrText(text1, text2)
            if (text3()) {
                printinfoOld('移动到底部了!!!')
                break;
            }
        }

        if (typeof (text4) == 'function') {
            findView = ocrText(text1, text2, text3)
            if (text4()) {
                printinfoOld('移动到底部了!!!')
                break;
            }
        }

        if (typeof (text5) == 'function') {
            findView = ocrText(text1, text2, text3, text4)
            if (text5()) {
                printinfoOld('移动到底部了!!!')
                break;
            }
        }


        findView = ocrText(text1, text2, text3, text4, text5)
        // SystemPrint.log('dfsdfsdf')

        maxTimes = maxTimes - 1
        if (maxTimes <= 0) {
            break
        }

        if (canBreak && canBreak()) {
            printinfoOld('移动到底部了!!!')
            break
        }
    }

    if (findView != null) {
        if (funC) {
            funC(findView)
        }
    } else {
        if (failBack) failBack()
    }
}

function moveUp2FindWidTxtMoreByTimes(times, funC, text1, text2, text3, text4, text5, canBreak, failBack) {
    // SystemPrint.log(typeof (text1) == 'function')
    if (times == undefined) times = 4
    var maxTimes = times
    //    SystemPrint.log(parseInt(uiText.findByID(控件ID = 'move_maxtimes').getText()) + 1)
    var findView = ocrText(text1, text2, text3, text4, text5)

    while (findView == null
        || findView.getRealRect().getTop() > screen.percentToHeight(0.88)
        || findView.getRealRect().getBottom() < screen.percentToHeight(0.1)) {

        if (findView == null) {
            agentSwipDownMove(false)
            sleep.millisecond(2000)
        } else {
            if (findView.getRealRect().getBottom < screen.percentToHeight(0.1)) {
                agentSwipSmallUp()
                sleep.millisecond(2000)
            }
            if (findView.getRealRect().getTop() > screen.percentToHeight(0.88)) {
                agentSwipSmallDown()
                sleep.millisecond(2000)
            }
        }

        if (typeof (text2) == 'function') {
            findView = ocrText(text1)
            if (text2()) {
                printinfoOld('移动到底部了!!!')
                break;
            }
        }

        if (typeof (text3) == 'function') {
            findView = ocrText(text1, text2)
            if (text3()) {
                printinfoOld('移动到底部了!!!')
                break;
            }
        }

        if (typeof (text4) == 'function') {
            findView = ocrText(text1, text2, text3)
            if (text4()) {
                printinfoOld('移动到底部了!!!')
                break;
            }
        }

        if (typeof (text5) == 'function') {
            findView = ocrText(text1, text2, text3, text4)
            if (text5()) {
                printinfoOld('移动到底部了!!!')
                break;
            }
        }


        findView = ocrText(text1, text2, text3, text4, text5)
        // SystemPrint.log('dfsdfsdf')

        maxTimes = maxTimes - 1
        if (maxTimes <= 0) {
            break
        }

        if (canBreak && canBreak()) {
            printinfoOld('移动到底部了!!!')
            break
        }
    }

    if (findView != null) {
        if (funC) {
            funC(findView)
        }
    } else {
        if (failBack) failBack()
    }
}

function moveUpHigher2FindWidTxtMore(funC, text1, text2, text3, text4, text5, canBreak, failBack) {
    // SystemPrint.log(typeof (text1) == 'function')
    var maxTimes = parseInt(uiText.findByID(控件ID = 'move_maxtimes').getText())
    var findView = ocrText(text1, text2, text3, text4, text5)

    log('开始查找' + text1 + '次数' + maxTimes)
    while (findView == null
        || findView.getRealRect().getTop() > screen.percentToHeight(0.76)
        || findView.getRealRect().getBottom() < screen.percentToHeight(0.15)) {

        if (findView == null) {
            agentSwipDownMove(false)
            sleep.millisecond(2200)
        } else {
            if (findView.getRealRect().getBottom < screen.percentToHeight(0.15)) {
                agentSwipSmallUp()
            }
            if (findView.getRealRect().getTop() > screen.percentToHeight(0.76)) {
                agentSwipSmallDown()
                sleep.millisecond(1800)
            }
        }

        if (typeof (text2) == 'function') {
            findView = ocrText(text1)
            if (text2()) {
                printinfoOld('移动到底部了!!!')
                break;
            }
        }

        if (typeof (text3) == 'function') {
            findView = ocrText(text1, text2)
            if (text3()) {
                printinfoOld('移动到底部了!!!')
                break;
            }
        }

        if (typeof (text4) == 'function') {
            findView = ocrText(text1, text2, text3)
            if (text4()) {
                printinfoOld('移动到底部了!!!')
                break;
            }
        }

        if (typeof (text5) == 'function') {
            findView = ocrText(text1, text2, text3, text4)
            if (text5()) {
                printinfoOld('移动到底部了!!!')
                break;
            }
        }


        findView = ocrText(text1, text2, text3, text4, text5)
        // SystemPrint.log('dfsdfsdf')

        maxTimes = maxTimes - 1
        if (maxTimes <= 0) {
            break
        }

        if (canBreak && canBreak()) {
            printinfoOld('移动到底部了!!!')
            break
        }
    }

    if (findView != null) {
        if (funC) {
            funC(findView)
        }
    } else {
        if (failBack) failBack()
    }
}

function moveUptepBack2FindWidTxtMore(funC, stepback, text1, text2, text3, text4, text5, canBreak, failBack) {
    // SystemPrint.log(typeof (text1) == 'function')
    var maxTimes = parseInt(uiText.findByID(控件ID = 'move_maxtimes').getText())
    var findView = ocrText(text1, text2, text3, text4, text5)

    while (findView == null
        || findView.getRealRect().getTop() > screen.percentToHeight(0.88)
        || findView.getRealRect().getBottom() < screen.percentToHeight(0.1)) {

        if (findView == null) {
            agentSwipDownMove(false)
            sleep.millisecond(2200)
        } else {
            if (findView.getRealRect().getBottom < screen.percentToHeight(0.1)) {
                agentSwipSmallUp()
            }
            if (findView.getRealRect().getTop() > screen.percentToHeight(0.88)) {
                agentSwipSmallDown()
                sleep.millisecond(1800)
            }
        }

        if (stepback) {
            stepback()
        }

        if (typeof (text2) == 'function') {
            findView = ocrText(text1)
            if (text2()) {
                printinfoOld('移动到底部了!!!')
                break;
            }
        }

        if (typeof (text3) == 'function') {
            findView = ocrText(text1, text2)
            if (text3()) {
                printinfoOld('移动到底部了!!!')
                break;
            }
        }

        if (typeof (text4) == 'function') {
            findView = ocrText(text1, text2, text3)
            if (text4()) {
                printinfoOld('移动到底部了!!!')
                break;
            }
        }

        if (typeof (text5) == 'function') {
            findView = ocrText(text1, text2, text3, text4)
            if (text5()) {
                printinfoOld('移动到底部了!!!')
                break;
            }
        }


        findView = ocrText(text1, text2, text3, text4, text5)
        // SystemPrint.log('dfsdfsdf')

        maxTimes = maxTimes - 1
        if (maxTimes <= 0) {
            break
        }

        if (canBreak && canBreak()) {
            printinfoOld('移动到底部了!!!')
            break
        }
    }

    if (findView != null) {
        if (funC) {
            funC(findView)
        }
    } else {
        if (failBack) failBack()
    }
}


// file.delete('/sdcard/aiworklog.txt')
// write2Text('test')
// write2Text('test233')

function write2Text(str, isAppend) {
    if (!isEnableSwitch('enablelog')) {
        return
    }

    if (isAppend == undefined) isAppend = true


    var current = new Date();
    var hours = current.getHours().toString().padStart(2, '0');
    var minutes = current.getMinutes().toString().padStart(2, '0');



    txt.writeTxt('/sdcard/aiworklog.txt', hours + ':' + minutes + '--' + str + '\n', isAppend)
}

function getLoginfo() {

    return txt.readFileSdcardt('/sdcard/aiworklog.txt')
}

function setExcuteFunc(funcName, hasExcute) {
    if (hasExcute == undefined) hasExcute = 'true'
    config.setConfig('/sdcard/config.ini', funcName, hasExcute)
}

/**
 * @param seconds = 3600
 */
function setExcuteFuncInTime一段时间内不再执行(funcName, seconds) {
    if (seconds == undefined) seconds = 3600

    var originalDate = new Date();  // 当前时间
    var newTime = originalDate.getTime() + (seconds * 1000);  // 将秒数转换为毫秒数并进行相加
    originalDate.setTime(newTime);
    // SystemPrint.log(originalDate.getTime())
    // config.setConfig('/sdcard/config.ini', 'test', originalDate.getTime())

    config.setConfig('/sdcard/config.ini', funcName + 'intime', originalDate.getTime())
}

function setForverExcuteFuncInTime一段时间内不再执行(funcName, seconds) {
    if (seconds == undefined) seconds = 3600

    var originalDate = new Date();  // 当前时间
    var newTime = originalDate.getTime() + (seconds * 1000);  // 将秒数转换为毫秒数并进行相加
    originalDate.setTime(newTime);
    // SystemPrint.log(originalDate.getTime())
    // config.setConfig('/sdcard/config.ini', 'test', originalDate.getTime())
    config.setConfig('/sdcard/configForver.ini', funcName + 'intime', originalDate.getTime())
}


function hasExcuteFunc(funcName) {
    var flag = config.getConfig('/sdcard/config.ini', funcName, 'false') == 'true'
    if (flag) {
        printinfoOld(funcName + '任务已经完成!!!')
    }
    return flag
}

function hasExcuteFuncInTime是否在一段时间内执行过(funcName) {
    var fetureTime = config.getConfig('/sdcard/config.ini', funcName + 'intime', 0)
    var diff = fetureTime - Date.now()
    //  SystemPrint.log(diff/1000)

    // var flag = config.getConfig('/sdcard/config.ini', funcName, 'false') == 'true'
    if (diff > 0) {
        printinfoOld(funcName + '执行过了!!!' + '还需' + Math.floor(diff / 1000) + '秒---' + Math.floor(diff / 1000 / 60) + '分')
        return true
    }
    return false
}

function getExcuteFuncInTime一段时间内执行过还需多少时间(funcName) {
    var fetureTime = config.getConfig('/sdcard/config.ini', funcName + 'intime', 0)
    var diff = fetureTime - Date.now()
    //  SystemPrint.log(diff/1000)
    // var flag = config.getConfig('/sdcard/config.ini', funcName, 'false') == 'true'
    if (diff > 0) {
        printinfoOld(funcName + '执行过了!!!' + '还需' + Math.floor(diff / 1000) + '秒---' + Math.floor(diff / 1000 / 60) + '分')
        return `${Math.floor(diff / 1000 / 60)}分`
    }
    return '0秒'
}


function hasForverExcuteFuncInTime是否在一段时间内执行过(funcName) {
    var fetureTime = config.getConfig('/sdcard/configForver.ini', funcName + 'intime', 0)
    var diff = fetureTime - Date.now()
    //  SystemPrint.log(diff/1000)
    // var flag = config.getConfig('/sdcard/config.ini', funcName, 'false') == 'true'
    if (diff > 0) {
        printinfoOld(funcName + '执行过了!!!' + '还需' + Math.floor(diff / 1000) + '秒---' + Math.floor(diff / 1000 / 60) + '分')
        return true
    }
    return false
}

function setConfig(key, value) {
    config.setConfig('/sdcard/config.ini', key, value)
}

function getConfig(key) {
    return config.getConfig('/sdcard/config.ini', key, 'false')
}


function getENVConfig(key) {
    return config.getConfig('/sdcard/envconfig.ini', key, 'false')
}

function setENVConfig(key, value) {
    config.setConfig('/sdcard/envconfig.ini', key, value)
}

function ENV() {
    // SystemPrint.log(config.getConfig('/sdcard/envconfig.ini', 'ENV', 'test'))
    return config.getConfig('/sdcard/envconfig.ini', 'ENV', 'test')
}

function getExcuteFuncTimes(funcName) {
    var excutetimes = parseInt(config.getConfig('/sdcard/config.ini', funcName + 'times', 0))

    if (!funcName.includes('start_app')) {
        printinfoOld('获取到' + funcName + ": " + excutetimes)
    }

    return excutetimes
}

// function setExcuteFuncTimes(funcName, defaultNum) {
//     if (defaultNum == undefined) {
//         config.setConfig('/sdcard/config.ini', funcName + 'times', defaultNum)
//     } else {
//         config.setConfig('/sdcard/config.ini', funcName + 'times', defaultNum)
//     }
// }

function addExcuteFuncTimes(funcName, defaultNum) {
    if (defaultNum == undefined) {
        var times = getExcuteFuncTimes(funcName) + 1
        printinfoOld(`当前次数为: ${times}`)
        config.setConfig('/sdcard/config.ini', funcName + 'times', times)
    } else {
        config.setConfig('/sdcard/config.ini', funcName + 'times', defaultNum)
    }
}

function clearData() {
    printinfoOld('清除所有数据')
    file.delete('/sdcard/config.ini')
    file.delete('/sdcard/aiworklog.txt')
    file.delete('/sdcard/aiworkdebug.txt')
}

function setForverExcuteFunc(funcName) {
    config.setConfig('/sdcard/configForver.ini', funcName, 'true')
}

function hasForverExcuteFunc(funcName) {
    return config.getConfig('/sdcard/configForver.ini', funcName, 'false') == 'true'
}

function getForverExcuteFuncTimes(funcName) {
    return parseInt(config.getConfig('/sdcard/configForver.ini', funcName + 'times', 0))
}

function addForverExcuteFuncTimes(funcName, defaultNum) {
    if (defaultNum == undefined) {
        var times = getForverExcuteFuncTimes(funcName) + 1
        config.setConfig('/sdcard/configForver.ini', funcName + 'times', times)
    } else {
        config.setConfig('/sdcard/configForver.ini', funcName + 'times', defaultNum)
    }
}



function getDectNumber(dect, index) {
    if (index == undefined) index = 0
    if (!dect) {
        return 0
    }

    var findNums = dect.text().match(/\d+/g);
    if (findNums && findNums.length > index) {

        printinfoOld('获取到的数字: ' + findNums[index])
        return Number(findNums[index])
    }

    return 0
}


function getDectFloatNumber(dect, index) {
    if (index == undefined) index = 0
    if (!dect) {
        return 0
    }
    // SystemPrint.log('0oO'.replace('O', '0'))
    // 修改正则表达式以匹配小数
    var findNums = dect.text().replace('O', '0').match(/\d+\.?\d*/g);
    if (findNums && findNums.length > index) {

        printinfoOld('获取到的数字: ' + findNums[index])
        return Number(findNums[index])
    }

    return 0
}


function getNumber(str, index) {
    if (index == undefined) index = 0
    if (str == null) {
        return -1
    }

    var findNums = str.match(/\d+/g);
    if (findNums && findNums.length > index) {
        return Number(findNums[index])
    }

    return 0
}



/**
 * @param packName 包名 -> currentAppPackName
 */
function reStartApp(packName) {
    if (packName == undefined) packName = currentAppPackName
    startApp(packName, true)
    sleep.millisecond(1000)
}

// startApp('com.ss.android.article.lite')

function isAllow允许登录(packName) {
    var findApp = APP_NAME_MAPPING.find(item => item.value == packName)
    if (findApp) {
        // SystemPrint.log(SKIPAPPS)
        if (SKIPAPPSArray.find(item => item == findApp.label)) {
            SystemPrint.warn(findApp.label + '已屏蔽,不允许允许!')
            print.warn(findApp.label + '已屏蔽,不允许允许!')
            return false
        }
    }

    return true
}

/**
 * @param packName 包名
 */
function startApp(packName, isSkip弹窗和青少年以及判断) {
    if (isSkip弹窗和青少年以及判断 == undefined) isSkip弹窗和青少年以及判断 = true;
    if (app.getAppName(packName) == '') {
        return false
    }

    // 判断是否允许登录
    // if (!isAllow允许登录(packName)) {
    //     return false
    // }

    if (currentAppPackName == 'com.kwai.theater') {
        if (hasExcuteFunc('xf_未登陆')) {
            log('喜番未登录今日跳过')
            return false
        }
    }

    try {
        app.openApp(packName)
    } catch (err) {
        app.openAppv2(packName)
    }


    //    printl( app.getAppName('com.kuaishou.kgx.novel') == '')
    currentAppPackName = packName
    sleep.millisecond(200)

    // for
    if (!hasExcuteFunc('is_auto_login' + packName) || isBetweenTime(0, 3)) {
        agentOrHidClick(ocrWaitForMoreTextMillisecondInRegion(0, 0.8, 0.9, 1, 2, '始终允许', '允许'), 1, () => {
            // ocrText('拒绝', true)
            setExcuteFunc('is_auto_login' + packName)
            agentOrHidClickAbsoultX(ocrTextMoreInRegion(0, 0.7, 1, 1, '取消', '拒绝', '打开'), screen.percentToWidth(0.75))
            agentOrHidClickAbsoultX(ocrTextMoreInRegion(0, 0.7, 1, 1, '取消', '拒绝'), screen.percentToWidth(0.75))
        })
        addExcuteFuncTimes('is_auto_login' + packName)
        if (getExcuteFuncTimes('is_auto_login' + packName) > 3) {
            setExcuteFunc('is_auto_login' + packName)
        }

    }

    if (!hasForverExcuteFunc('is_success_login' + packName)) {
        if (ocrWaitForMoreTextMillisecond('个人信息保护', '保护指引', '个人信息处理', '欢迎使用喜', '一键登录', '阅读并同意', 10)) {
            return false
        }

        if (ocrText('个人信息保护', '保护指引', '个人信息处理', '欢迎使用喜', '你的公开信息')) {
            return false
        }

        if (currentAppPackName == 'com.kwai.theater') {
            if (ocrText('用户协议', '隐私政策', '欢迎使用喜')) {
                setExcuteFunc('xf_未登陆')
                return false
            }
        }
        setForverExcuteFunc('is_success_login' + packName)
    }


    if (isBetweenTime(0, 4) || isBetweenTime(18, 24)) {
        if (!isSkip弹窗和青少年以及判断 && !hasExcuteFunc('is_qsn_login' + packName)) {
            agentOrHidClick(ocrTextMoreInRegion(0.2, 0.6, 0.8, 1, '打开', '我知道了')) // 
            agentOrHidClick(ocrText('以后再说', '取消'))
            setExcuteFunc('is_qsn_login' + packName)
        }
    }

    agentOrHidClick(ocrWaitForTextMillisecondInRegion(0.5, 0.05, 0.95, 0.15, '跳过', 2))


    return true
}

function agentOrHidHome() {
    if (ENABLE_BLUE_MODE) {
        hid.home()
        return
    }

    if (ENABLE_HID_MODE) {
        Otg.home() //hid.home()
    } else {
        agent.home()
    }
}

function closeApp(packName) {
    // app.openAppSeting(packName)

    // // sleep.millisecond(500)

    // // ocrText('强行停止', true)
    // agentOrHidClick(ocrWaitForMoreTextMillisecond('强行停止', '停止'), 500, () => {
    //     // agentClickRight(ocrTextMoreInRegionComplete(0, 0.5, 1, 0.87, '强行停止', '停止'), 1)
    //     // ocrText('取消', true)
    //     agentOrHidClickAbsoultX(ocrTextMoreInRegionComplete(0, 0.5, 1, 0.97, '取消', '停止', '|取消'), screen.percentToWidth(0.75))

    // })

    // // sleep.millisecond(200)
    // agentOrHidHome()
    // sleep.millisecond(2000)
}


// stopAllApp()
function stopAllApp(isfullscreen) {
    if (isfullscreen == undefined) isfullscreen = false

    // app.openApp('com.android.settings')
    // sleep.millisecond(300)

    // closeApp('com.android.settings')


    sleep.millisecond(200)
    if (!hasForverExcuteFunc('phone型号')) {
        agentOrHidHome()
        sleep.second(2)
        if (ocrText('软件商店', '软件商')) {
            setForverExcuteFunc('vivo')
        }
        if (ocrText('应用市场', '应用市')) {
            setForverExcuteFunc('huawei')
        }
        setForverExcuteFunc('phone型号')
    }

    if (ENABLE_HID_MODE) {
        if (hasForverExcuteFunc('vivo') || isEnableSwitch('is_upclear')) {
            printinfoOld('vivo')
            agentOrHidHome()
            sleep.second(1)
            // hid.recents()
            // sleep.second(1)
            if (ENABLE_BLUE_MODE) {
                // hid.touchDown(0, screen.percentToWidth(0.5), screen.percentToHeight(1) - 25)
                // sleep.millisecond(500)
                hid.swip(screen.percentToWidth(0.5), screen.percentToHeight(1) - 25,
                    screen.percentToWidth(0.5), screen.percentToHeight(0.45), 150, 50, 50)
                // sleep.millisecond(500)
                // hid.touchUp(0)
            } else {
                Otg.swipe(screen.percentToWidth(0.5), screen.percentToHeight(1) - 10, screen.percentToWidth(0.6), screen.percentToHeight(0.75), 100, 50, 50)
            }
            // if (ENABLE_BLUE_MODE) {
            //     printinfoOld('ENABLE_BLUE_MODE')
            //     hid.recents()
            //     sleep.second(1)
            // } else {
            //     Otg.recents()
            // }
            sleep.millisecond(500)
            agentOrHidClick(ocrWaitForText('清除', '除'))
            return
            //Otg.swipeAI(screen.percentToWidth(0.5), screen.percentToHeight(1), screen.percentToWidth(0.6), screen.percentToHeight(0.75))
        } else {
            if (ENABLE_BLUE_MODE) {
                hid.recents()
            } else {
                Otg.recents()
            }

        }
    } else {
        agent.recents()
    }

    sleep.millisecond(500)
    printinfoOld('stopall -> step0')
    expectView(() => {
        //    printinfoOld('step0')
        if (isfullscreen) {
            var detectsclearfull = opencv.findImagesEx('图色359882.cv');
            if (detectsclearfull != null && detectsclearfull.length > 0) {
                return detectsclearfull[0]
            } else {
                return ocrTextMoreComplete('清除')
            }
        } else {
            var detectsclear = opencv.findImagesEx('图色897511.cv');
            printinfoOld('stopall -> step1')
            if (detectsclear == null) {
                detectsclear = opencv.findImagesEx('图色701489.cv');
                printinfoOld('stopall -> step2')
            }
            if (detectsclear != null && detectsclear.length > 0) {
                // printinfoOld(detects);
                return detectsclear[0]
                // agentOrHidClick(detects[0], 1)
            } else {
                agentOrHidClick(ocrTextInRegion(0, 0.3, 0.5, 0.8, '不允许'))
            }
        }

        return null
    }, () => {
        // printinfoOld('step1')
        sleep.millisecond(500)
    }, (findView) => {
        //  printinfoOld('step2')
        agentOrHidClick(findView)
    }, () => {
        click(0.5, 0.9)
    }, 4)
}


function clearMsg() {
    if (ENABLE_BLUE_MODE) {
        hid.swip(screen.percentToWidth(0.2), screen.percentToHeight(0), screen.percentToWidth(0.2), screen.percentToHeight(0.5), 25, 100, 100)
    } else {
        if (ENABLE_HID_MODE) {
            Otg.swipe(screen.percentToWidth(0.2), screen.percentToHeight(0), screen.percentToWidth(0.2), screen.percentToHeight(0.5), 25, 100, 100)
        } else {
            agent.swip(screen.percentToWidth(0.2), screen.percentToHeight(0), screen.percentToWidth(0.2), screen.percentToHeight(0.5), 2, 100, 100)
        }
    }

    sleep.second(1)

    var detectsclear = opencv.findImagesEx('图色897511.cv');
    if (detectsclear == null) {
        detectsclear = opencv.findImagesEx('图色701489.cv');
    }
    if (detectsclear != null) {
        agentOrHidClick(detectsclear[0])
    }

}
/**
 * @param sleepSecond 执行的时间秒
 * @param functionStep  回调(stepTimes: 执行次数, allTimes: 执行总的时间秒)
 */
function startSplitScreenApp(sleepSecond, appName1, appName2, functionApp1Back, functionApp2Back,
    allAppStartBack, functionStep, endBack, failStart) {
    // 先启动第一个app进行初始化, 
    // todo
    // 启动第二个app进行初始化, 
    // 第二个进行分屏
    // 再次启动第一个
    var issuccess1 = startApp(APP_NAME_MAPPING.find(item => item.label == appName1).value)
    if (!issuccess1) {
        SystemPrint.warn('appName1: ' + appName1 + '不存在, 跳过')
    } else {
        functionApp1Back && functionApp1Back()
    }
    sleep.millisecond(500)


    var issuccess2 = startApp(APP_NAME_MAPPING.find(item => item.label == appName2).value)
    if (!issuccess2) {
        SystemPrint.warn('appName2: ' + appName2 + '不存在, 跳过')
    } else {
        functionApp2Back && functionApp2Back()

    }

    if (!issuccess1 && !issuccess2) {
        return
    }

    sleep.millisecond(500)
    agentOrHidHome()
    sleep.millisecond(500)

    // 两个都再存在才会分屏
    if (issuccess1 && issuccess2) {
        if (ENABLE_BLUE_MODE) {
            hid.recents()
        } else {
            if (ENABLE_HID_MODE) {
                Otg.recents() //hid.recents()
            } else {
                agent.recents()
            }
        }

        sleep.millisecond(1000)

        //找图返回目标数组 华为手机直接上滑进入分屏
        var detects = opencv.findImagesEx('图色926185.cv');
        if (detects != null) {
            printinfoOld('华为手机开始分屏')
            startApp(APP_NAME_MAPPING.find(item => item.label == appName2).value, true)

            if (ENABLE_BLUE_MODE) {
                hid.swip(screen.percentToWidth(0.5), screen.percentToHeight(0.98), screen.percentToWidth(0.15), screen.percentToHeight(0.1), 25, 100, 100)
            } else {
                if (ENABLE_HID_MODE) {
                    Otg.swipe(screen.percentToWidth(0.5), screen.percentToHeight(0.98), screen.percentToWidth(0.15), screen.percentToHeight(0.1), 25, 100, 100)
                } else {
                    agent.swip(screen.percentToWidth(0.5), screen.percentToHeight(0.98), screen.percentToWidth(0.15), screen.percentToHeight(0.1), 2, 100, 100)
                    // agent.swip(screen.percentToWidth(0.5), screen.percentToHeight(0.98), screen.percentToWidth(0.15), screen.percentToHeight(0.1), 20, 100, 100)
                }
            }

            sleep.millisecond(1500)
            agentOrHidClickOffectY(ocrTextMoreComplete(appName1), 100)
        } else {
            //找图返回目标数组
            var detects = opencv.findImagesEx('图色608484.cv');
            if (detects != null) {
                //    printinfoOld(detects);
                agentOrHidClick(detects[0])
            } else {
                sleep.millisecond(1000)
                detects = opencv.findImagesEx('图色608484.cv');
                if (detects != null) {
                    //    printinfoOld(detects);
                    agentOrHidClick(detects[0])
                } else {
                    failStart && failStart()
                    return
                }
            }

            agentOrHidClick(ocrWaitForMoreTextMillisecond('分屏', 4, 500))
            // 重新启动完成分屏
            startApp(APP_NAME_MAPPING.find(item => item.label == appName1).value, true)
        }
    } else {
        if (issuccess1) {
            startApp(APP_NAME_MAPPING.find(item => item.label == appName1).value, true)
        }
        if (issuccess2) {
            startApp(APP_NAME_MAPPING.find(item => item.label == appName2).value, true)
        }
    }

    allAppStartBack && allAppStartBack(issuccess1, issuccess2)
    sleep.millisecond(500)

    agentOrHidClick(ocrWaitForMoreTextMillisecondInRegion(0, 0.9, 1, 1, 4, '稍后提示'))
    whilestep(functionStep, sleepSecond, 5)

    printinfoOld('分屏循环任务完成!!!')
    //  结束所有app
    // app.closeApp(APP_NAME_MAPPING.find(item => item.label == appName1).value)
    // app.closeApp(APP_NAME_MAPPING.find(item => item.label == appName2).value)

    if (issuccess1 && issuccess2) {
        //分屏的标志图片
        var detectssplit = opencv.findImagesEx('图色147562.cv');
        if (detectssplit != null) {
            var splitReact = detectssplit[0].getRealRect()
            // printinfoOld(detectssplit[0].getRealRect().getTop())
            //  printinfoOld(detectssplit[0].getRealRect().getTop())

            if (ENABLE_BLUE_MODE) {
                hid.swip(splitReact.getCenterX(), splitReact.getCenterY(), splitReact.getCenterX(), screen.percentToHeight(0.05), 25, 200, 100)
            } else {
                if (ENABLE_HID_MODE) {
                    Otg.swipe(splitReact.getCenterX(), splitReact.getCenterY(), splitReact.getCenterX(), screen.percentToHeight(0.05), 25, 200, 100)
                } else {
                    agent.swip(splitReact.getCenterX(), splitReact.getCenterY(), splitReact.getCenterX(), screen.percentToHeight(0.05), 2, 200, 100)
                    // agent.swip(screen.percentToWidth(0.5), screen.percentToHeight(0.98), screen.percentToWidth(0.15), screen.percentToHeight(0.1), 20, 100, 100)
                }
            }


        }
    }

    // closeApp(APP_NAME_MAPPING.find(item => item.label == appName2).value)
    stopAllApp()
    // closeApp(APP_NAME_MAPPING.find(item => item.label == appName2).value)
    // stopAllApp()

    endBack && endBack()
}

function showEnterMainpageInfo展示进入任务弹窗信息() {
    if (APP_NAME_MAPPING.find(item => item.value == currentAppPackName)) {

        printinfoOld(APP_NAME_MAPPING.find(item => item.value == currentAppPackName).label + '进入到任务中心完成!!!')
        sleep.second(1)

        sleep.millisecond(200)
    }
}


function isMainTaskAAA养鸡刷金完成() {
    // if (!isAllow允许登录(PACK_NAME_YS) && (!isAllow允许登录(PACK_NAME_HG) || hasExcuteFunc('open_开宝箱_HG'))) {
    //     // setExcuteFunc('main_task_完成')
    //     return true
    // }
    if ((!isAllow允许登录(PACK_NAME_HG) || hasExcuteFunc('open_开宝箱_HG'))) {
        // setExcuteFunc('main_task_完成')
        return true
    }


    return false
}

/**
 * envmode, morellmode
 */
function isEnableSwitch(modStr) {
    if (uiSwitch.findByID(控件ID = modStr) && uiSwitch.findByID(控件ID = modStr).getOn()) {
        // printinfoOld('enableSwitch : ' + modStr)
        return true
    }
    return false
}

function isRunAppTask(appName, taskname) {
    var taskame = hui.getCheck(appName).getValue()
    var taskDetail = taskame.split(',')
    return taskDetail.find(item => item == taskname)
}

function get电池电量() {
    printinfoOld('get电池电量')

    if (ENABLE_BLUE_MODE) {
        hid.swip(screen.percentToWidth(0.8), 10,
            screen.percentToWidth(0.8), screen.percentToHeight(0.5), 25, 100, 0)
    } else {
        if (ENABLE_HID_MODE) {
            Otg.swipe(screen.percentToWidth(0.8), 10,
                screen.percentToWidth(0.8), screen.percentToHeight(0.5), 25, 100, 0)
        } else {
            agent.swip(screen.percentToWidth(0.7), 10, screen.percentToWidth(0.7), screen.percentToHeight(0.5), 2, 100, 0)
        }
    }


    ocrWaitForMoreTextMillisecondInRegion(0, 0, 1, 0.3, 4, '控制中心', '蓝牙')
    sleep.millisecond(500)

    var ocr1 = opencv.OCREx('图色730718.cv');
    agentOrHidHome()
    if (ocr1 != null) {
        if (parseInt(ocr1.getAllString()) > 100) {
            var allDect = ocr1.getAllDetect()
            var sortdect = allDect.sort((a, b) => a.score - b.score)
            var limit = [sortdect[0], sortdect[1]]
            var limitsort = limit.sort((a, b) => a.getRealRect().getCenterX() - b.getRealRect().getCenterX())
            // printl(limitsort)
            // printl(parseInt(sortdect[0].text() + sortdect[1].text()))
            return parseInt(limitsort[0].text() + limitsort[1].text())
        }

        printinfoOld('当前电量: ' + ocr1.getAllString())
        return parseInt(ocr1.getAllString())
    }
    return 80
}

function getRandomNum(start, end) {
    return Math.floor(Math.random() * (end - start) + start)
}

function close多余的弹窗() {
    // var detects = opencv.findImagesEx('图色243468.cv');
    // if (detects != null) {
    //     agentOrHidClick(detects[0])
    // }

    var detectsapp弹窗 = opencv.findImagesEx('图色897625.cv');
    if (detectsapp弹窗 != null) {
        agentOrHidClick(detectsapp弹窗[0])
    }
}

function isLastDateOfCurrentMonth() {
    var date = new Date();
    var next_date = new Date(date.getTime() + 24 * 60 * 60 * 1000).getDate();
    if (next_date == 1) {
        return true;
    }
    return false;
};

/**获取最大的数字 */
function getMaxNumber(str) {
    printocrinfo(str)
    // 使用正则表达式匹配所有的数字
    var numbers = str.match(/(\d+)/g) || [];
    // 转换为数字数组并找到最大值
    return Math.max.apply(null, numbers.map(function (n) { return parseInt(n, 10); }));
}

// 计算两个字符串的最长公共子序列长度
function longestCommonSubsequence(str1, str2) {
    const m = str1.length;
    const n = str2.length;
    const dp = Array.from({ length: m + 1 }, () => Array(n + 1).fill(0));

    for (let i = 1; i <= m; i++) {
        for (let j = 1; j <= n; j++) {
            if (str1[i - 1] === str2[j - 1]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            } else {
                dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }

    if (!dp[m]) {
        return 1
    }

    return dp[m][n];
}

// 计算两个字符串的相似度百分比
function calculateSimilarityPercentage(str1, str2) {
    if (!str1) return 0
    if (str1.length === 0 && str2.length === 0) return 100;
    const lcsLength = longestCommonSubsequence(str1, str2);
    const maxLength = Math.max(str1.length, str2.length);
    return (lcsLength / maxLength) * 100;
}


function getMaxNumByStr(str) {
    var numbers = str.match(/(\d+)/g) || [];
    // SystemPrint.log(numbers.toString())

    // return numbers
    // 转换为数字数组并找到最大值
    return Math.max.apply(null, numbers.map(function (n) { return parseInt(n, 10); }));
}


function logFull(str, showTime) {

    new floatUI().closeAll()
    //初始化一个activity页面
    var fuifull = new floatUI()

    fuifull.loadXML(`
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="8dp">
    <TextView
       android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="textViewfull"
        android:size="18"
        android:text=""
        android:textColor="#FF000000"
         android:lineSpacingExtra="8dp" 
        />
</LinearLayout>
`)
    fuifull.setPosition(50, 0)
    fuifull.setHeight(screen.percentToHeight(1))

    var _textViewFull = fuifull.findViewById('textViewfull');
    if (_textViewFull != null) {
        try {
            _textViewFull.setText(str)
        } catch (error) {

        }
    }
    SystemPrint.log(str)
    sleep.second(showTime)
    fuifull.close()
}

function log(str) {
    if (_textView) {
        try {
            _textView.setText(str)
        } catch (error) {

        }
    }
    SystemPrint.log(str)
}

/**
 * sleepTime 默认2秒
 */
function logSleep(str, sleepTime) {
    log(str)
    if (sleepTime == undefined) sleepTime = 2
    sleep.second(sleepTime)
}

function logSleepTime(str, sleepTime) {
    log(str)
    if (sleepTime == undefined) sleepTime = 2
    for (let i = 0; i < sleepTime; i++) {
        sleep.second(1)
        log('剩余广告时长' + (sleepTime - i - 1))
    }
}

function show展示低金币的标志位() {
    // if (_textViewlow != null) {
    //     try {
    //         _textViewlow.setText(`${getConfig('ct_total') < 100000 ? "听" : ""}${getConfig('ctyy_total') < 100000 ? "音" : ""}`)
    //     } catch (error) {

    //     }
    // }
    SystemPrint.log(str)
}



